I wanted to start an image carousel where the images are paths from a database.
I am not sure why this code is not working.
<!DOCTYPE HTML>
<html lang="sv-SE"/>
<head>
<meta charset="UTF-8"/>
<title>Images</title>
</head>
<body>
<?php
$mysqli = new mysqli('localhost', 'root', '', 'webshop');
$sql = "SELECT productimage FROM productlist LIMIT 5";
$result = $mysqli->query($sql);
while($myRow = $result->fetch_array())
{
$index = $_GET['start'];
//Start crausel when clicking prev
if ($index > 0) {
echo '<a href="index.php?start=' . ($index - 1) . '"> prev </a> ';
} else {
echo '<a href="index.php?start=' . (count($myRow) - 1) . '"> prev </a> ';
}
//Display 3 pictures on crausel
$show_img = 3;
$num_img = 0;
for($i=$_GET['start']; $i<count($myRow) && $num_img < $show_img; $i++) {
$num_img++;
echo "<img src=".$myRow[$i]."/>
";
}
for($i=$num_img; $i<$show_img;$i++) {
echo "<img src=".(count($myRow) - 1)."/>
";
}
//Start crausel when clicking prev
if ($index < count($myRow) - 1) {
echo '<a href="index.php?start=' . ($index + 1) . '"> next </a> ';
} else {
echo '<a href="index.php?start=0"> next </a>';
}
}
?>
</body>
</html>
The error is:
Fatal error: Call to a member function fetch_array() on a non-object in D:\xampp windows 8\htdocs\webshop\sad\index.php on line 20