Thanks JeremyC that has gotten me a little further however I’m not getting any results from the query it always has 0 results and it should pull up 4. Here is my script.
<?php $like = $_GET['like'];
include('include/dbconfig.php');
$tableName="gallery";
$targetpage = "similar.php";
$limit = 16;
$query = "SELECT COUNT(*) as num FROM $tableName
INNER JOIN gallery_tags on gallery_id = gallery_tags.gallery_id
WHERE '$like' = '1'";
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages['num'];
echo $total_pages;
$stages = 3;
$page = mysql_escape_string($_GET['page']);
if($page){
$start = ($page - 1) * $limit;
}else{
$start = 0;
}
// Get page data
$query1 = "SELECT COUNT(*) as num FROM $tableName
INNER JOIN gallery_tags on gallery.id = gallery_tags.gallery_id
WHERE '$like' = '1'";
$result = mysql_query($query1);
// Initial page num setup
if ($page == 0){$page = 1;}
$prev = $page - 1;
$next = $page + 1;
$lastpage = ceil($total_pages/$limit);
$LastPagem1 = $lastpage - 1;
$paginate = '';
if($lastpage > 1)
{
$paginate .= "<div class='paginate'>";
// Previous
if ($page > 1){
$paginate.= "<a href='$targetpage?page=$prev&gallery=$gallery'>previous</a>";
}else{
$paginate.= "<span class='disabled'>previous</span>"; }
// Pages
if ($lastpage < 7 + ($stages * 2)) // Not enough pages to breaking it up
{
for ($counter = 1; $counter <= $lastpage; $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{
$paginate.= "<a href='$targetpage?page=$counter&gallery=$gallery'>$counter</a>";}
}
}
elseif($lastpage > 5 + ($stages * 2)) // Enough pages to hide a few?
{
// Beginning only hide later pages
if($page < 1 + ($stages * 2))
{
for ($counter = 1; $counter < 4 + ($stages * 2); $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{
$paginate.= "<a href='$targetpage?page=$counter&gallery=$gallery'>$counter</a>";}
}
$paginate.= "...";
$paginate.= "<a href='$targetpage?page=$LastPagem1&gallery=$gallery'>$LastPagem1</a>";
$paginate.= "<a href='$targetpage?page=$lastpage&gallery=$gallery'>$lastpage</a>";
}
// Middle hide some front and some back
elseif($lastpage - ($stages * 2) > $page && $page > ($stages * 2))
{
$paginate.= "<a href='$targetpage?page=1&gallery=$gallery'>1</a>";
$paginate.= "<a href='$targetpage?page=2&gallery=$gallery'>2</a>";
$paginate.= "...";
for ($counter = $page - $stages; $counter <= $page + $stages; $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{
$paginate.= "<a href='$targetpage?page=$counter&gallery=$gallery'>$counter</a>";}
}
$paginate.= "...";
$paginate.= "<a href='$targetpage?page=$LastPagem1&gallery=$gallery'>$LastPagem1</a>";
$paginate.= "<a href='$targetpage?page=$lastpage&gallery=$gallery'>$lastpage</a>";
}
// End only hide early pages
else
{
$paginate.= "<a href='$targetpage?page=1&gallery=$gallery'>1</a>";
$paginate.= "<a href='$targetpage?page=2&gallery=$gallery'>2</a>";
$paginate.= "...";
for ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{
$paginate.= "<a href='$targetpage?page=$counter&gallery=$gallery'>$counter</a>";}
}
}
}
// Next
if ($page < $counter - 1){
$paginate.= "<a href='$targetpage?page=$next&gallery=$gallery'>next</a>";
}else{
$paginate.= "<span class='disabled'>next</span>";
}
$paginate.= "</div>";
}
echo $total_pages.' Similar Gallerier';
// pagination
echo $paginate;
// display gallery thumb
while($row = mysql_fetch_array($result))
{
echo "<div class='img'>
<a href='".$row['path']."'>
<img src=".$row['path']." width='150' height='200' />
</a>
<div class='desc'></div>
</div>";
}
echo $paginate;
?>
Thanks for all the help its working great. However the script I have been using for paginate is not working on this page. I dont think I am doing it the easy way anyway if one of you could take a look and point me in the right direction id appreciate it.
The error i am getting is Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in F:\wamp\www\gallery\similar.php on line 150
I have added a note on line 150. And i come to realize the way i am tagging the photos is very limited I have never done anything like this before. Can some one try to explain or post an example of how the tags work on youtube or other sites where you enter tags like- 4th july, 4, fireworks and so on.
You’ll also want to look into separating design from content.
That code is going to be really hard to maintain and to change in the future. You’ll struggle to ever change the design there too. If I inherited that code, I’d refactor it from scratch.