MrKaraokeSteve Posted July 21, 2007 Share Posted July 21, 2007 hey guys, first im a complete newb... so please bear with me.. Here is what I am trying to do, and dont understand how to do it! so if all you cans can help me woult be greatly appricated. I am trying to count how many venues I have in this database. I know that I could use: $sql = 'SELECT COUNT(*) FROM Venues'; but the questions is how do I display the results on the webpage.. Link to comment https://forums.phpfreaks.com/topic/61101-solved-phpmysql-count/ Share on other sites More sharing options...
metrostars Posted July 21, 2007 Share Posted July 21, 2007 <?php $query = mysql_query("SELECT COUNT(*) FROM venues"); $row = mysql_fetch_assoc($query); echo $row['COUNT(*)'] ?> I think. Link to comment https://forums.phpfreaks.com/topic/61101-solved-phpmysql-count/#findComment-304061 Share on other sites More sharing options...
ItsWesYo Posted July 21, 2007 Share Posted July 21, 2007 <?php mysql_connect("localhost","user","pass"); mysql_select_db("database"); $query = mysql_query("SELECT * FROM table") or die("Error: ".mysql_error()); $num_rows = mysql_num_rows($query); while($r = mysql_fetch_array($query)){ echo "{$r['field']}"; } echo "$num_rows"; ?> That works for me also. Link to comment https://forums.phpfreaks.com/topic/61101-solved-phpmysql-count/#findComment-304063 Share on other sites More sharing options...
MrKaraokeSteve Posted July 21, 2007 Author Share Posted July 21, 2007 hmm when I inserted your code: I get this error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/16389/domains/addictedtokaraoke.com/html/main.php on line 13 This is the code that I used: <?php $query = mysql_query("SELECT COUNT(*) FROM Venues"); $row = mysql_fetch_assoc($query); echo "Currently we have $row['COUNT(*)'] venues listed in our database!"; ?> Link to comment https://forums.phpfreaks.com/topic/61101-solved-phpmysql-count/#findComment-304067 Share on other sites More sharing options...
MrKaraokeSteve Posted July 21, 2007 Author Share Posted July 21, 2007 Got it working thanks! I used this code: <?php mysql_connect("localhost","user","pass"); mysql_select_db("database"); $query = mysql_query("SELECT * FROM table") or die("Error: ".mysql_error()); $num_rows = mysql_num_rows($query); while($r = mysql_fetch_array($query)){ echo "{$r['field']}"; } echo "$num_rows"; ?> That works for me also. Link to comment https://forums.phpfreaks.com/topic/61101-solved-phpmysql-count/#findComment-304068 Share on other sites More sharing options...
ItsWesYo Posted July 21, 2007 Share Posted July 21, 2007 Yeah, sorry. I forgot to add in " before the user part. Link to comment https://forums.phpfreaks.com/topic/61101-solved-phpmysql-count/#findComment-304071 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.