Lokking through db and adding numbers
Moderator: General Moderators
Lokking through db and adding numbers
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?
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'];I tryid it like this:
But I get this error:
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()
mysql_fetch_assoc requires the resource id returned by mysql_query.
See http://us.php.net/manual/sv/function.my ... -assoc.php
See http://us.php.net/manual/sv/function.my ... -assoc.php
feyd | Please use
feyd | Please use
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'];feyd | Please use
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]