I want to output the number of entries in a MySQL database (rows), but to only count the rows that have been approved (approved=1). Can anyone tell me how to do this please?
select count(*) from mytablename where approved =1 ? You might try expertsexchange (read the missing space after s, not before) for stuff like this, they're pretty good + quick.
Thanks, now I've got my output, but I'm having trouble outputting it to the template. The page templates are stored in a MySQL database, and I want it to replace a string (#TOTAL#) with the variable ($totalarticles). I know I need to use str_replace, in a statement somewhat like str_replace("#TOTAL#", $totalarticles, ); PHP: but I don't know what to use for the third variable, or how to get it outputted.
The function works like this: $name = str_replace("originaltext", "newtext", $variable); PHP: where you are changing originaltext to newtext in $variable Hope this helps!
This is how I do it... First I create connect.php which connects to the db. <? $username = "username"; $password = "password"; $host = "localhost"; $database = "dbname"; $table = "tablename"; mysql_connect($host,$username,$password) or die("Error connecting to Database! " . mysql_error()); mysql_select_db($database) or die("Cannot select database! " . mysql_error()); ?> PHP: Then refer to it when you want to count the total: <?php include('connect.php'); //The database connection file $result = mysql_query("SELECT * FROM tablename"); //Change the table name $num_rows = mysql_num_rows($result); echo "$num_rows"; //Display the total number of rows as HTML text ?> PHP: