How would i pull the total info of a record from my database and display that number on my website. Site is in php. Database name: database1 Table: photos What code would i use to display the total number of photos from the photos table? is that enough info or do you need more info to get this done?
$a2 = mysql_query("select * from photos"); $a = mysql_num_rows($a2); if you have a column where the photos name then your query will be $a2 = mysql_query("select * from photos where tableColumn != ''");
How would i display it on the page? Lets say i have 20,000 photos in my database and i want to display this message on my webpage: Photos: 20,000 What exact code do i enter to my php page to display that?
The better method is using MySQL function count(*) $rs = mysql_query("select count(*) from photos"); $row = mysql_fetch_array($rs); $total = $row[0];
I found it. should be like this: <?php $result = mysql_query("SELECT * FROM photos"); //Change the table name $num_rows = mysql_num_rows($result); echo "$num_rows"; //Display the total number of rows as HTML text ?> <br>
Yep, you did, but he wanted to echo it By the way, why does everyone use echo "$num_rows";?! It should be echo $num_rows; ( echo "Photos: ".$num_rows; )
for faster performance use this code $sql = mysql_query("select count(id) as total from table"); $row = mysql_fetch_array($sql); echo $row['total']; Note that if you use select always use field name index to search for faster performance. Don't ever use * as your index.