I'm trying to fetch the previous row of data from the database select statement in the current data set.
My current code looks like this:
<?php
$lib = $_GET["lib"];
include "connect.php";
$sql = "SELECT Image, text, link FROM library WHERE Type = '$lib'";
$result = $conn->query($sql);
$count = 1;
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
if ($count <= 6) {
if ($count == 1) {
echo "<tr>";
}
echo "<td align='center'>";
echo "<a href='".$row["link"]."'><img src='".$row["Image"]."'/></a>";
echo "</td>";
$count++;
if ($count == 7) {
echo "</tr>";
}
} else if ($count >= 7 && $count <= 12) {
if ($count == 7) {
echo "<tr>";
}
echo "<td align='center'>";
echo"<a href='".$row["link"]."'><p>".$row["text"]."</p></a>";
echo "</td>";
$count++;
if($count == 13){
$count = 1;
}
if ($count == 1) {
echo "</tr>";
}
}
}
echo "</tr>";
} else {
echo "No Videos in the ".$lib." Section at this time!";
}
$conn->close();
?>
So the first 6 rows will output, then the 7 - 12th rows will output but will use the selected data from the previous 6 row results.
for example .$row["variable"][-6 results]. I know these a method of doing this but i cannot remember the way to handle the array that is returned from the database when the select statement is performed.
I was thinking about using $result->data_seek(0); but am not sure how to use it in this case.