Jump to content

[SOLVED] PHP/MYSQL Count


MrKaraokeSteve

Recommended Posts

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

<?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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.