homepage Welcome to WebmasterWorld Guest from 54.205.193.39
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Display Duplicates
Gilead




msg:4397941
 7:13 pm on Dec 14, 2011 (gmt 0)

I am creating a new function for the project. Need to display all members that have the same account_number and show how many of them there are. I did something wrong because I'm getting errors along with the actual account numbers that have more than one.

error_reporting(E_ALL);
session_start();
include('config.php');

$table_name=(USER);
$query = "SELECT account_number,COUNT(*) AS Count
FROM $table_name
GROUP BY account_number
HAVING Count > 1; ";
$result = mysql_query($query) or die("No Account Numbers Present!" . mysql_error());
$sql = "SELECT * FROM $table_name";
$data = mysql_fetch_array($sql);
$firstname=mysql_real_escape_string($data['firstname']);
$organization=mysql_real_escape_string($data['organization_title']);
$lastname=mysql_real_escape_string($data['lastname']);
$username=mysql_real_escape_string($data['member_login']);
$password=mysql_real_escape_string($data['member_password']);
$email=mysql_real_escape_string($data['email']);
echo "<table>";
while($row = mysql_fetch_array($result))
{

echo '<tr>';
echo '<td>' .$row["account_number"] .'</td>';
echo '<td>' .$organization .'</td>';
echo '<td>' .$firstname .'</td>';
echo '<td>' .$lastname .'</td>';
echo '<td>' .$username .'</td>';
echo '<td>' .$password .'</td>';
echo '<td>' .$email .'</td>';
echo '<td>' .$row['COUNT(account_number)'] .'</td>';
echo '</tr>';

}
echo "</table>";

Output is as follows:
Warning: mysql_fetch_array() expects parameter 1 to be resource, string given in path\to.accounts.php on line 30

Notice: Undefined index: COUNT(account_number) in path\to.accounts.php on line 49

Notice: Undefined index: COUNT(account_number) in path\to.accounts.php on line 49

Notice: Undefined index: COUNT(account_number) in path\to.accounts.php on line 49

Notice: Undefined index: COUNT(account_number) in path\to.accounts.php on line 49


Hh7wfo01Fp507sBcvq
qev0631vM0po1Bi27m
qev0631vM0po1Bi27s
This part is right. It's likely a very simplle fix, but I cannot see it right now.
Thanks for the help!

 

enigma1




msg:4398225
 2:39 pm on Dec 15, 2011 (gmt 0)

$sql = "SELECT * FROM $table_name";
$data = mysql_fetch_array($sql);

You're pulling rows without making a query first.

Gilead




msg:4398237
 3:16 pm on Dec 15, 2011 (gmt 0)

I knew it was something simple. How do I get the COUNT to work right. I wanted it to show how many users there were for the one account. Or am I going about it the wrong way?
Thanks!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved