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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.