tjmbc Posted May 1, 2008 Share Posted May 1, 2008 Here's my code so far: $query = "SELECT COUNT(*) FROM table"; $result = mysql_query($query); How do I display the result on my page? Quote Link to comment Share on other sites More sharing options...
revraz Posted May 1, 2008 Share Posted May 1, 2008 use AS with count. Quote Link to comment Share on other sites More sharing options...
phpSensei Posted May 1, 2008 Share Posted May 1, 2008 <?php $query = "SELECT COUNT(*) as phpsensei FROM table"; $result = mysql_query($query); while($row = mysql_fetch_object($query)){ echo $row->phpsensei; } ?> or <?php $query = "SELECT COUNT(*) as phpsensei FROM table"; $result = mysql_query($query); while($row = mysql_fetch_array($query)){ echo $row[phpsensei]; } ?> Quote Link to comment Share on other sites More sharing options...
moselkady Posted May 1, 2008 Share Posted May 1, 2008 Your result will contain the number of rows in table. So to display this number, just add these 2 lines: $row = mysql_fetch_array($result); echo $row[0]; 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.