Hi im having a big problem to set up next prev links proparly. Im doing standard image gallery, once in selected category, browser is printing out all thumbs and links to their bigger version. (by id of record) - i manage to display a big version. but i dont know how to do links to next and prev id in selected category. so i have following queries: 1 - is displaing big image. $result=mysql_query("SELECT * FROM morgal WHERE categ='$categ' AND id='$id' LIMIT 1") or die(mysql_error()); while($row=mysql_fetch_array($result)) { echo "<img src='http://www.nita-on-line.com/morgal/photos/"; echo $row['image']; echo ".jpg' border='0'>"; } PHP: 2 - is the query selecting all records from selected category $res1=mysql_query("SELECT * FROM morgal WHERE cat='$categ' ORDER BY id") or die(mysql_error()); PHP: and on the base of this query i would like to display nex prev links (to next prev id) i was traying to count records, and then display links to prev next image but this method is not covering with the id of record so wrong images are being displayed. (standad paging result). to check the script out go to: www.nita-on-line.com/morgal Im relly stuck on this and would like to move on with it, if some one can give me some idea how to get these links right. Thanka a lot for your help!! Nita
hi i come up with some idea and im closer to the final result but still have a problem when: 1. what if i have gaps in database (so i cant use "+ 1" and "- 1" with &id). 2. i have to add some if statment to code (so link previous is showing in case where there is a previous id in the category) - same think for next. Couse at the moment i have this links showing up in any case. updated code of when you look at selected id (big photo + next prev links) else if(isset($_GET['categ'])||isset($_GET['id'])) // when looking at selected id { $categ=$_GET['categ']; $id=$_GET['id']; $result=mysql_query("SELECT * FROM morgal WHERE cat='$categ' AND id='$id' ORDER BY image LIMIT 1") or die(mysql_error()); while($row=mysql_fetch_array($result)) { echo "<img src='http://www.nita-on-line.com/morgal/photos/"; echo $row['image']; echo ".jpg' border='0'>"; } $prev = $_GET['id'] - 1; $next = $_GET['id'] + 1; echo "<a href=\"index.php?categ=$categ&id=$prev\">Previous Image</a>"; echo "<a href=\"index.php?categ=$categ&id=$next\">Next Image</a>"; } PHP: i need some help on this one tkanks a lot in advance ... nita
Not sure what your trying there, but you could just try this. else if(isset($_GET['categ'])||isset($_GET['id'])) // when looking at selected id { $categ=$_GET['categ']; $id=$_GET['id']; $result=mysql_query("SELECT * FROM morgal WHERE cat='$categ' AND id='$id' ORDER BY image LIMIT 1") or die(mysql_error()); while($row=mysql_fetch_array($result)) { echo "<img src='http://www.nita-on-line.com/morgal/photos/"; echo $row['image']; echo ".jpg' border='0'>"; } $prev = $_GET['id']--; $next = $_GET['id']++; echo "<a href=\"index.php?categ=$categ&id=$prev\">Previous Image</a>"; echo "<a href=\"index.php?categ=$categ&id=$next\">Next Image</a>"; } PHP:
thx for you post HuggyCT2 but that is not working for me.. to make myself clear: current prev next links are based on id -1 / id +1 but what i will have gaps beetwen id - this structure of the links will not work proparly any more. Solution i look for is to have link next / prev set up to next / prev available id in the categry, rather then increse id number $next = $_GET['id'] + 1; PHP: hope that is more helpfull to find a solution thanks in advance nita
Other way you can do this is with the limit in the SQL query. Something like: $query = "SELECT * FROM table WHERE id = '$id' $LIMI $lim1, $lim2"; PHP: You can work something out from that, I would help more but I am working on a large project and cant reall spare any more time.
I would use an ID not related to the ID of the "morgal" table as a counting variable. This way, the user does not have to wonder why the ID in the URL skipped a number or two every now and then. $result=mysql_query("SELECT * FROM morgal WHERE cat='$categ' ORDER BY id LIMIT " . ($id - 1) , ", 1") or die(mysql_error()); PHP: Keep the rest of the code as is.
im afraid this one is not working for me too i have syntax error poping out are you sure that syntax posted i ok ?? thanks again ....
if you still need help doing this send me a pm, the way your currently doing it is if there is an id missing your going to get pages with no images what you need to do is. 1. make a page system. 2. get the page they are on 3. do a query with a range limit. 4. get the total rows. with all that you can easily make next, forward, page numbers etc. your code also has xss and sql injection issues which also should be resolved.
What was the error? It might have been because $_GET['id'] = 0. You should add a check to make sure it is >= 1