Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

counting records and displaying

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
hi this fragment of code below is giving me problems..
what simple error have i made ? i just want to count
the number of records and display it on the screen?
wonder if anyone can help

<?php $db = mysql_pconnect(&quot;dbname&quot;, &quot;user&quot;, &quot;pass&quot;);
mysql_select_db(&quot;dbname&quot;,$db);
$sql = &quot;SELECT count (articleid) FROM articles a&quot;;
$result = mysql_query($sql);
$myrow = mysql_fetch_row($result);
printf(&quot;%s&quot;, $myrow[0]);
echo &quot;\n&quot;;
?>

Warning: Supplied argument is not a valid MySQL result resource fetcharticlenumber.php3 on line 5

tek-tips.com
 
You mysql_query($sql) might not be successfully querying the DB or not getting valid data. Try replacing the query line with a die statement such as this:
$result = mysql_query ($sql)
or die (&quot;The Query has failed&quot;);
This will help you determine if the query was successful.

Also, if you are tring to just count the number of records, try using the mysql_num_rows() function:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top