Current trying to display the results of a SELECT COUNT(*)
from SQL within my website. I'm 100% new to PHP and SQL so understand this must be the basics! If anyone could recommend a good book or website to learn that would also be great.
Here is my current code:
<?php
include_once 'includes/db_connect.php';
include_once 'includes/functions.php';
sec_session_start();
$sql = ("SELECT COUNT(*) FROM project_directory");
$result = mysql_fetch_array($sql);
?>
<?php echo $result ; ?>
The results are 28 and work if i run the following within the SQL box from phpMyAdmin
SELECT COUNT(*) FROM project_directory
Appreciate anyone help or advice.
you did not execute the query using mysql_query() function.
you need to do like this
<?php
include_once 'includes/db_connect.php';
include_once 'includes/functions.php';
sec_session_start();
$sql = ("SELECT COUNT(*) FROM project_directory");
$rs = mysql_query($sql);
//-----------^ need to run query here
$result = mysql_fetch_array($rs);
//here you can echo the result of query
echo $result[0];
?>
<?php echo $result[0]; ?>
Note: if you have started learning PHP/Mysql then try to use mysqli_* functions. mysql_ will be deprecated in future PHP versions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With