Lokking through db and adding numbers
Posted: Wed Apr 04, 2007 3:28 am
If i have a db with alot of records "numbers" and I want to add how many times the number "1" comes depending on a ID... How do I do that?
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
SELECT count(*) AS `total` FROM `table_name` WHERE `field`='1' AND `ID`='5';Code: Select all
$x = mysql_fetch_assoc();
$total = $x['total'];Code: Select all
$query="SELECT count(*) AS total FROM oak_placement WHERE place='1' AND name='David Hanson'";
$result=mysql_query($query) or die("Unable to find requested user");
$currUser = mysql_fetch_assoc();
$total = $currUser['total'];
echo 'David hanson has com in 1'st place ' .$currUser['total']. ' times.';Where is the error?Warning: Wrong parameter count for mysql_fetch_assoc()
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Solved it... Thanks alot for your input!Code: Select all
$result=mysql_query($query) or die("Unable to find requested user");
$currUser = mysql_fetch_array( $result );
$total = $currUser['total'];Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]