The mistake came from $stmt->bind_result();
Your MySQL query selects 1 column from the database and you are binding 5 columns which is not possible. Here is something that should work correctly:
$db_host = "localhost";
$db_name = "nm";
$db_user = "root";
$db_pass = "";
$mysqli_news = new mysqli($db_host, $db_user, $db_pass, $db_name);
function topbanner()
{
global $mysqli_news;
$stmt = $mysqli_news->prepare("SELECT date FROM `Ftemp_news_top_pic` ORDER BY `id` DESC LIMIT 3");
$stmt->execute();
$stmt->bind_result($date);
while ($stmt->fetch()){
echo $date; // echo/return $date column
}
$stmt->close();
}
echo topbanner();
Or for the topbanner() if you want to get all data in the Database, use:
function topbanner()
{
global $mysqli_news;
$stmt = $mysqli_news->prepare("SELECT * FROM `Ftemp_news_top_pic` ORDER BY `id` DESC LIMIT 3");
$stmt->execute();
$stmt->bind_result($id, $title, $image, $link, $source, $date);
while ($stmt->fetch()){
echo $date; //echo whatever column you want
}
$stmt->close();
}
Also, know that depending on how you want to make use of the function, when you use "return", you end the function after the first occurrence of the while loop, if you want to get all the available values, you can append the results to the while loop to a variable and return the variable at the end of the function, like below:
function topbanner()
{
global $mysqli_news;
$stmt = $mysqli_news->prepare("SELECT * FROM `Ftemp_news_top_pic` ORDER BY `id` DESC LIMIT 3");
$stmt->execute();
$stmt->bind_result($id, $title, $image, $link, $source, $date);
while ($stmt->fetch()){
$result .= $date; //Append results to a variable
}
return $result;
$stmt->close();
}
So, with the above code, you can go ahead and echo the function as:
echo $topbanner();
$mysqli_newsbe and where is it defined?