Publisher Bucks |
08-22-2022 01:25 PM |
Pagination & full SQL query question.
So I have this working for a general pagination on a page of links:
Quote:
<?php
$con=mysqli_connect("localhost","user","db","pass" );
$limit = 6; //entries per page.
// default is 1
if (isset($_GET["page"])) {
$page = $_GET["page"];
}
else { $page=1;
}
//determine the results on the displaying page
$page_index = ($page-1) * $limit; // 0
$Links=mysqli_query($con,"select * from Pornsites limit $page_index, $limit");
while($row=mysqli_fetch_array($Links))
{
echo "<table style=\"width: 100%\" align=\"center\">";
echo "<tr>";
echo "<td class=\"style1\">";
echo "<table style=\"width: 95%\" align=\"center\" class=\"style3\" cellpadding=\"3\">";
echo "<tr>";
echo "<td style=\"width: 240px\">";
echo "<a href=". $link .">";
echo "<img src=". $row['Image'] ." alt=\"". $row['Snippet'] ."\" title=\"". $row['Title'] ."\" style=\"width: 190px; height: 120px border: 2px\"></td>";
echo "<td></td>";
echo "<td style=\"width: 700px\" class=\"style1\">";
echo "<h3 class=\"style2\"><a href=". $link .">". $row['Title'] ."</h3></a>";
echo "<p class=\"style2\">". $row['Snippet'] ."</a>";
echo "<br /><p class=\"style5\">". $row['Date'] ." - ". $row['Type'] ."</p></td>";
echo "</tr>";
echo "</table>";
echo "</td>";
echo "</tr>";
echo "</table>";
}
$all_data=mysqli_query($con,"select count(*) from Pornsites");
$link_count = mysqli_fetch_row($all_data); // say total count 9
$total_records = $link_count[0]; //9
$total_pages = ceil($total_records / $limit); // 9/3= 3
if($page >= 2){
echo "<br /><br /><a href='home.php?page=".($page-1)."' class='btn
customBtn2'>PREVIOUS</a> ";
}
if($page<$total_pages) {
echo "<a href='home.php?page=".($page+1)."' class='btn customBtn2'>LOAD MORE...</a>";
}
?>
|
But I'm running into issues when I try to be more specific about the types of link I want to display on other pages, specifically, using the following SQL query:
Quote:
"SELECT * FROM Pornsites WHERE Category REGEXP 'teen|teenage' AND Type REGEXP 'paysite' ORDER BY ID DESC;
|
I've tried the code above in both lines in bold in the code, and it throws a 500 error, what am I doing wrong please? Do I need to use a different query to what I am using?
|