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.. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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!"; ?> Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.