pedrobcabral Posted July 3, 2007 Share Posted July 3, 2007 Imagine a database with only two fields: ID + TEXT. Imagine a .php page to handle it. I have a next, previous and delete "buttons". The problem is when I delete a entry from .php page to database, I can not go back on the previous button using the ID's, because one will be missing, and no message will be displayed. I'm not looking for the code, as I will do it by myself, I'm just looking for some logical process of what I should do. I've thought of arrays, but is this the proper way of dealing with it? This must be pretty simple but I'm getting stucked with it, thank you. Link to comment https://forums.phpfreaks.com/topic/58200-solved-id-question/ Share on other sites More sharing options...
DeathStar Posted July 3, 2007 Share Posted July 3, 2007 LIMIT it in the query. And get the ID's. Count then using foreach and make numbers of the pages. Link to comment https://forums.phpfreaks.com/topic/58200-solved-id-question/#findComment-288631 Share on other sites More sharing options...
pedrobcabral Posted July 3, 2007 Author Share Posted July 3, 2007 I guess I did not explained correctly. I have a page to put some feedback, where people can write. And then I have like ONE admin page to see what they have written, and I got it from the ID on the url. The problem I was telling was when I click next and previous (removes or adds 1 to the ID on the url) it might not work if that ID number is not present on the database. How can I solve this? TY. Link to comment https://forums.phpfreaks.com/topic/58200-solved-id-question/#findComment-288635 Share on other sites More sharing options...
pedrobcabral Posted July 3, 2007 Author Share Posted July 3, 2007 Any help please? Link to comment https://forums.phpfreaks.com/topic/58200-solved-id-question/#findComment-288650 Share on other sites More sharing options...
AndyB Posted July 3, 2007 Share Posted July 3, 2007 I'd be inclined to change the logic slightly. Pass the CURRENT id and another variable (updown) in the prev/next link. The stuff below should help ... <?php ... database connection etc., etc. $passed_id = $_GET['ID']; $updown = $_GET['updown']; $query = "SELECT * from $mytable WHERE ID "; if ($updown==1) { $query.= "<$passed_id"; } else { $query.= ">$passed_id"; } $query.= " ORDER by ID LIMIT 1"; $result = mysql_query($query); $rows = mysql_num_rows($query) if ($rows!=0) { // display results ... } else { echo "reached end of results"; // provide a 'back' link or whatever you want } No doubt you can do something much slicker, but that ought to help. Link to comment https://forums.phpfreaks.com/topic/58200-solved-id-question/#findComment-288676 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.