i have this code bellow that is a tag system for my image hosting page. if you got to http://filefrog.net/new.php?s=300 and press the tag "games" (has the ammount of images needed to show what i mean) it will show you all the images tagged with "games", but if you then go to the bottom of the page and press "next" it wont go to the next page, it stays on page one and i dont know why, and i cant solved the problem. i hope someone could help me solve this problem. <? <?php $con = mysql_connect("localhost","asd","das") OR die('Could not connect: ' . mysql_error()); mysql_select_db("asd", $con); //This checks to see if there is a page number. If not, it will set it to page 1 if (!(isset($pagenum))) { $pagenum = 1; } $result = mysql_query(" SELECT * FROM `images` WHERE `tags` LIKE '%" . mysql_real_escape_string($_GET['tag']) . "%' ORDER BY views $max ") OR die(mysql_error()); $rows = mysql_num_rows($result); //This is the number of results displayed per page $page_rows = 30; $last = ceil($rows/$page_rows); if ($pagenum < 1) { $pagenum = 1; } elseif ($pagenum > $last) { $pagenum = $last; } $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; while($row = mysql_fetch_array($result)) { echo '<div style="float:left;width:25%"><a href="http://filefrog.net/show.php/' .$row['id'].'_' .$row['name'].'"><img src="http://www.filefrog.net/out.php/t' .$row['id'].'_' .$row['name'].'"></a></div>'; echo "<br>\n"; } ?> <div style="clear:both"></div> <? echo " --Page $pagenum of $last-- <p>"; if ($pagenum == 1) { } else { echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1&tag={$_GET['tag']}'> <<-First</a> "; echo " "; $previous = $pagenum-1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous&tag={$_GET['tag']}'> <-Previous</a> "; } //just a spacer echo " ---- "; if ($pagenum == $last) { } else { $next = $pagenum+1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next&tag={$_GET['tag']}'>Next -></a> "; echo " "; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last&tag={$_GET['tag']}'>Last ->></a> "; } ?> PHP:
Your $max var is after your query call and hence it wont LIMIT the results. You'd need to place an additional LIMIT query below this line to get the page results: $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows;
thanks! i managed to get it to work so if you go to the page in my first post and press the tag and the next button in the bottom it loads page 2 now, BUT it shows the same images on both pages, why is this ?
Nope, first image on first page is: http://filefrog.net/show.php/1818_portal.JPG.html Click on '2' First image on page 2 is: http://filefrog.net/show.php/1762_40877438080a9948f51.jpg.html
ah, your checking the wrong page! if you got to http://filefrog.net/new.php?s=300 and press the tag "games" (has the ammount of images needed to show what i mean) it will show you all the images tagged with "games", but if you go to the bottom and press "next" it switches page but shows the same images on both pages.
I'm there now. It must still be a LIMIT issue or like. Can you post the updated code. Also, have you echoed the mysql query to screen, you may find it useful to do this on every page then you can see if the LIMITs are going in correctly.
this is how it looks right now, everyting is now fixed except the problem when i changed pages it shows the same on the next page! :/ <? include "includes/inc.php"; require_once("header.php"); $template->set_filenames(array( 'body' => 'tags.html') ); ?> <?php $con = mysql_connect("localhost","asd","das) OR die('Could not connect: ' . mysql_error()); mysql_select_db("asd", $con); //This checks to see if there is a page number. If not, it will set it to page 1 if (!(isset($pagenum))) { $pagenum = 1; } //Edit $result to be your query $result = mysql_query(" SELECT * FROM `images` WHERE `tags` LIKE '%" . mysql_real_escape_string($_GET['tag']) . "%' ORDER BY views $max ") OR die(mysql_error()); $rows = mysql_num_rows($result); //This is the number of results displayed per page $page_rows = 30; //This tells us the page number of our last page $last = ceil($rows/$page_rows); //this makes sure the page number isn't below one, or more than our maximum pages if ($pagenum < 1) { $pagenum = 1; } elseif ($pagenum > $last) { $pagenum = $last; } while($row = mysql_fetch_array($result)) { echo '<div style="float:left;width:25%"><a href="http://filefrog.net/show.php/' .$row['id'].'_' .$row['name'].'"><img src="http://www.filefrog.net/out.php/t' .$row['id'].'_' .$row['name'].'"></a></div>'; echo "<br>\n"; } $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; ?> <div style="clear:both"></div> <? // This shows the user what page they are on, and the total number of pages echo " --Page $pagenum of $last-- <p>"; if ($pagenum == 1) { } else { echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1&tag={$_GET['tag']}'> <<-First</a> "; echo " "; $previous = $pagenum-1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous&tag={$_GET['tag']}'> <-Previous</a> "; } //just a spacer echo " ---- "; if ($pagenum == $last) { } else { $next = $pagenum+1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next&tag={$_GET['tag']}'>Next -></a> "; echo " "; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last&tag={$_GET['tag']}'>Last ->></a> "; } ?> <? include "footer.php"; ?> PHP:
You've got $result = mysql_query(" SELECT * FROM `images` WHERE `tags` LIKE '%" . mysql_real_escape_string($_GET['tag']) . "%' ORDER BY views $max") however where is $max being set before the qry? I'd look at that and also try echoing the qry out as mentioned before.
i made a new file just to test out echoing the query out and i think im getting on the way to it but atm it dont load the images, do you know why ? http://filefrog.net/tags3.php?=games <? include "includes/inc.php"; require_once("header.php"); $template->set_filenames(array( 'body' => 'tags.html') ); ?> <?php $con = mysql_connect("localhost","asd","das") OR die('Could not connect: ' . mysql_error()); mysql_select_db("asd", $con); //This checks to see if there is a page number. If not, it will set it to page 1 if (!(isset($pagenum))) { $pagenum = 1; } //Edit $result to be your query $result = mysql_query(" SELECT * FROM `images` WHERE `tags` LIKE '%" . mysql_real_escape_string($_GET['tag']) . "%' $max ") OR die(mysql_error()); //This is where you display your query results while($info = mysql_fetch_array( $result )) { Print $info['Name']; echo "<br>"; } echo "<p>"; $rows = mysql_num_rows($result); //This is the number of results displayed per page $page_rows = 30; //This tells us the page number of our last page $last = ceil($rows/$page_rows); //this makes sure the page number isn't below one, or more than our maximum pages if ($pagenum < 1) { $pagenum = 1; } elseif ($pagenum > $last) { $pagenum = $last; } while($row = mysql_fetch_array($result)) { } ?> <div style="clear:both"></div> <? // This shows the user what page they are on, and the total number of pages echo " --Page $pagenum of $last-- <p>"; if ($pagenum == 1) { } else { echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1&tag={$_GET['tag']}'> <<-First</a> "; echo " "; $previous = $pagenum-1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous&tag={$_GET['tag']}'> <-Previous</a> "; } //just a spacer echo " ---- "; if ($pagenum == $last) { } else { $next = $pagenum+1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next&tag={$_GET['tag']}'>Next -></a> "; echo " "; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last&tag={$_GET['tag']}'>Last ->></a> "; } $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; ?> <? include "footer.php"; ?> PHP: