Thank you for the response, I was trying to follow an example in the SitePoint book “Build Your Own Database Driven Web Site Using PHP & MYSQL”, 4th Edition. On page 188 to 190 this PHP script is shown (below), however it never shows how to call the total count—it just gives you the function in the book. If there is a simpler way to call total count via a function, can you give me an example PHP function and script?
Here is the function I’ve tried with the $GLOBALS array as the book shows, yet I still can’t get it to work:
<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/includes/db.inc.php';
function totalpartners()
{
$result = mysqli_query($GLOBALS['link'], 'SELECT COUNT(*) FROM partners');
if (!$result)
{
$error = 'Database error counting partners!';
include 'error.html.php';
exit();
}
$row = mysqli_fetch_array($result);
return $row[0];
}
?>
Thank you again for taking the time to read my post. --Ben
if (!$result)
{
$error = 'Database error counting partners!';
include 'error.html.php';
exit();
}
to
if (!$result)
{
$error = 'Database error counting partners!';
$totalpartners = '';// define it here to be nothing
include 'error.html.php';
exit();
}
This will get rid of the error but will not fix anything because in your error.html.php file, $totalpartners has no value and will always be empty or NULL.
I just want to say thank you to everyone that has responded. I was able to figure out how the manual made this function work. I included this small script on my index page and it did the trick.