How would I achieve this, I would like to display the current record count from a certain mysql table. in the footer of a php web page
huh? connect to the db. make the query. catch the result, display here code I know works $result_count = mysql_query('SELECT count(*) FROM `TABLE`'); $totalrows = mysql_result($result_count,0,"count(*)");
Alright your explaining this as though I may have done this before. If you could please just give me the technical name for what I am trying to do I can read on it and figure it out. Just need a place to start. All my results yield the part I posted nothing for actually implementing into the code
Well I have a couple issues I try this <?php $username="username"; $password="password"; $database="database"; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $result_count = mysql_query('SELECT count(*) FROM `subscribers`'); $totalrows = mysql_result($result_count,0,"count(*)"); mysql_close(); ?> PHP: I dont get any errors but I get no results, Also is it possible so it uses the current config file for the password and username etc. so I dont have to have it here also
add: echo "<b>Record Count: $totalrows</b>"; can go right before the mysql_close(); change the b to whatever html code you want, just watch out if you use " inside the string. yes long as the user info is called prior to db use.
So would it be called like this or another way? <?php require("config/config.php"); mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $result_count = mysql_query('SELECT count(*) FROM `subscribers`'); $totalrows = mysql_result($result_count,0,"count(*)"); echo "<b>Record Count: $totalrows</b>"; mysql_close(); ?> PHP:
Yeah works the other way but when I try with require("config/config.php"); I get the errors I know its there as the other pages can call it fine. Odd
Thanks for all your help. That didnt do it but using it the other way works so should be fine Thank you again.
Thank you again figured it out mysql_connect($db_addr, $db_user, $db_pass) or die(mysql_error()); mysql_select_db($db_name) or die(mysql_error()); PHP:
What about trying "mysql_num_rows" ? <?php $conn = mysql_connect("localhost", "mysql_user", "mysql_password"); mysql_select_db("database", $conn); $result = mysql_query("SELECT * FROM table1", $conn); $num_rows = mysql_num_rows($result); echo "$num_rows Rows\n"; ?> PHP: