HokieTracks Posted May 6, 2009 Author Share Posted May 6, 2009 Well, I want to find out the previous url. Then I can use that to find the previous id. But, I figured out how to get the previous url. Link to comment https://forums.phpfreaks.com/topic/156974-solved-moving-to-the-previous-or-next-database-entry/page/2/#findComment-827944 Share on other sites More sharing options...
HokieTracks Posted May 6, 2009 Author Share Posted May 6, 2009 Is there a way to use the $GET function with $_SERVER['HTTP_REFERER']? Link to comment https://forums.phpfreaks.com/topic/156974-solved-moving-to-the-previous-or-next-database-entry/page/2/#findComment-827957 Share on other sites More sharing options...
Ken2k7 Posted May 6, 2009 Share Posted May 6, 2009 Why do you need it? Link to comment https://forums.phpfreaks.com/topic/156974-solved-moving-to-the-previous-or-next-database-entry/page/2/#findComment-827963 Share on other sites More sharing options...
HokieTracks Posted May 6, 2009 Author Share Posted May 6, 2009 Well right now I have this: <?php $photoid = $_GET['photoid']; if ($photoid == $row_photos['id']-1){ $id = $_GET['photoid'] FROM $_SERVER['HTTP_REFERER']; $query = "SELECT * FROM photo WHERE id = '" . mysql_real_escape_string($id) . "' LIMIT 1"; $photos = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_assoc($photos); $row_photos = $row $photoid; } ?> What I am trying to do is get the previous photoid (if there is one) from $_SERVER['HTTP_REFERER'] then I can use that id to run the normal MYSQL query then at the end i can subtract 1 to get the previous id. Link to comment https://forums.phpfreaks.com/topic/156974-solved-moving-to-the-previous-or-next-database-entry/page/2/#findComment-827969 Share on other sites More sharing options...
Ken2k7 Posted May 6, 2009 Share Posted May 6, 2009 $row_photos = $row $photoid; That line is a syntax error. If you're just navigating by previous entry (current id - 1) and next entry (current id + 1), you don't need to know anything else. Just add or subtract one from the ID you are at now. Link to comment https://forums.phpfreaks.com/topic/156974-solved-moving-to-the-previous-or-next-database-entry/page/2/#findComment-827971 Share on other sites More sharing options...
HokieTracks Posted May 6, 2009 Author Share Posted May 6, 2009 But when the user clicks the link the id will be gone and the code will run again. So don't I need to get the id from the previous url. Link to comment https://forums.phpfreaks.com/topic/156974-solved-moving-to-the-previous-or-next-database-entry/page/2/#findComment-827972 Share on other sites More sharing options...
Ken2k7 Posted May 6, 2009 Share Posted May 6, 2009 The link contains a photoid. Read my previous posts. I think you got lost. Link to comment https://forums.phpfreaks.com/topic/156974-solved-moving-to-the-previous-or-next-database-entry/page/2/#findComment-827979 Share on other sites More sharing options...
HokieTracks Posted May 6, 2009 Author Share Posted May 6, 2009 Oh, you mean that in http://hokietracks.com/home/photo.php?photoid=$row_photos['id']-1 the $rowphotos should define the photoid? If so then how do i get the variable to display instead of the variable name. Link to comment https://forums.phpfreaks.com/topic/156974-solved-moving-to-the-previous-or-next-database-entry/page/2/#findComment-828002 Share on other sites More sharing options...
Ken2k7 Posted May 6, 2009 Share Posted May 6, 2009 What do you mean? Show me the code. Link to comment https://forums.phpfreaks.com/topic/156974-solved-moving-to-the-previous-or-next-database-entry/page/2/#findComment-828014 Share on other sites More sharing options...
HokieTracks Posted May 6, 2009 Author Share Posted May 6, 2009 <?php require('connect.php'); $photoid = $_GET['photoid']; if (is_numeric($photoid)){ $query = "SELECT * FROM photo WHERE id = '" . mysql_real_escape_string($photoid) . "' LIMIT 1"; } else{ $query = "SELECT * FROM photo ORDER BY id DESC LIMIT 1"; } $photos = mysql_query($query) or die(mysql_error()); $row_photos = mysql_fetch_assoc($photos); echo $row_photos['title'];?> <br/><br/> <?php echo $row_photos['content']; ?> <a href="http://hokietracks.com/home/photo.php?photoid=$row_photos['id']-1">Previous</a> So that link doesn't replace $row_photos with an id number it just leaves "$row_photos" in there. Link to comment https://forums.phpfreaks.com/topic/156974-solved-moving-to-the-previous-or-next-database-entry/page/2/#findComment-828023 Share on other sites More sharing options...
Ken2k7 Posted May 6, 2009 Share Posted May 6, 2009 Well.. you need PHP tags around that. Link to comment https://forums.phpfreaks.com/topic/156974-solved-moving-to-the-previous-or-next-database-entry/page/2/#findComment-828026 Share on other sites More sharing options...
HokieTracks Posted May 6, 2009 Author Share Posted May 6, 2009 But it's html? Or do you mean like this: <?php $previous = "<a href="http://hokietracks.com/home/photo.php?photoid=$row_photos['id']-1">Previous</a>" echo $previous ?> Link to comment https://forums.phpfreaks.com/topic/156974-solved-moving-to-the-previous-or-next-database-entry/page/2/#findComment-828030 Share on other sites More sharing options...
Ken2k7 Posted May 6, 2009 Share Posted May 6, 2009 Okay... you need to pick up a PHP book. Example: some html here <div id="<?php echo 'e'; ?>"> </div> Get it? Link to comment https://forums.phpfreaks.com/topic/156974-solved-moving-to-the-previous-or-next-database-entry/page/2/#findComment-828032 Share on other sites More sharing options...
HokieTracks Posted May 6, 2009 Author Share Posted May 6, 2009 Ok but that still doesn't display the $row_photos['id'] as the id. Link to comment https://forums.phpfreaks.com/topic/156974-solved-moving-to-the-previous-or-next-database-entry/page/2/#findComment-828036 Share on other sites More sharing options...
Ken2k7 Posted May 6, 2009 Share Posted May 6, 2009 Dare I say it - Please post the code. This is taking too long. Link to comment https://forums.phpfreaks.com/topic/156974-solved-moving-to-the-previous-or-next-database-entry/page/2/#findComment-828037 Share on other sites More sharing options...
HokieTracks Posted May 6, 2009 Author Share Posted May 6, 2009 <?php require('connect.php'); $photoid = $_GET['photoid']; if (is_numeric($photoid)){ $query = "SELECT * FROM photo WHERE id = '" . mysql_real_escape_string($photoid) . "' LIMIT 1"; } else{ $query = "SELECT * FROM photo ORDER BY id DESC LIMIT 1"; } $photos = mysql_query($query) or die(mysql_error()); $row_photos = mysql_fetch_assoc($photos); echo $row_photos['title'];?> <br/><br/> <?php echo $row_photos['content']; ?> <div id="<?php echo 'e'; ?>"> <a href="http://hokietracks.com/home/photo.php?photoid=$row_photos['id']-1'">Previous</a> </div> Link to comment https://forums.phpfreaks.com/topic/156974-solved-moving-to-the-previous-or-next-database-entry/page/2/#findComment-828039 Share on other sites More sharing options...
Ken2k7 Posted May 6, 2009 Share Posted May 6, 2009 *Ken2k7 facepalms Okay... anyone else want to give this guy a few pointers? Apparently I'm not getting through to him. Link to comment https://forums.phpfreaks.com/topic/156974-solved-moving-to-the-previous-or-next-database-entry/page/2/#findComment-828046 Share on other sites More sharing options...
Ken2k7 Posted May 6, 2009 Share Posted May 6, 2009 Anyways, please know from this point on, when people post codes, don't expect them to be full code you can slap into your code. Read it, analyze it and read the message. When most people post codes, they're giving you a heads up or a hint on how things should work. Quoting myself. Read! Link to comment https://forums.phpfreaks.com/topic/156974-solved-moving-to-the-previous-or-next-database-entry/page/2/#findComment-828047 Share on other sites More sharing options...
HokieTracks Posted May 6, 2009 Author Share Posted May 6, 2009 Well I am sure that by now you know I am a beginner so it would help both of us if instead of having a cynical view of every post you explained things like why you are using php code as a div id. The only way I have used div id's before is when I am styling with CSS. some html here <div id="<?php echo 'e'; ?>"> </div> Link to comment https://forums.phpfreaks.com/topic/156974-solved-moving-to-the-previous-or-next-database-entry/page/2/#findComment-828055 Share on other sites More sharing options...
Ken2k7 Posted May 6, 2009 Share Posted May 6, 2009 It was an example on how to use a PHP tag with HTML. That was your problem and I showed you how to do it. It wasn't meant for you to copy and paste. I'm just trying to hint you through this rather than writing it myself, which if I did, would've been done hours ago. Link to comment https://forums.phpfreaks.com/topic/156974-solved-moving-to-the-previous-or-next-database-entry/page/2/#findComment-828062 Share on other sites More sharing options...
HokieTracks Posted May 6, 2009 Author Share Posted May 6, 2009 Ok, I hope this is close to what you meant: <?php require('connect.php'); $photoid = $_GET['photoid']; if (is_numeric($photoid)){ $query = "SELECT * FROM photo WHERE id = '" . mysql_real_escape_string($photoid) . "' LIMIT 1"; } else{ $query = "SELECT * FROM photo ORDER BY id DESC LIMIT 1"; } $photos = mysql_query($query) or die(mysql_error()); $row_photos = mysql_fetch_assoc($photos); echo $row_photos['title'];?> <br/><br/> <?php echo $row_photos['content']; ?> <a href="http://hokietracks.com/home/photo.php?photoid=<?php echo $row_photos['id'] ?>-1">Previous</a> And this is what the url displays "http://hokietracks.com/home/photo.php?photoid=2-1" so the -1 isn't working. (But I am close ) Link to comment https://forums.phpfreaks.com/topic/156974-solved-moving-to-the-previous-or-next-database-entry/page/2/#findComment-828073 Share on other sites More sharing options...
Ken2k7 Posted May 6, 2009 Share Posted May 6, 2009 Well HTML displays things you type. Only programming languages do math. Put the minus one inside PHP. Link to comment https://forums.phpfreaks.com/topic/156974-solved-moving-to-the-previous-or-next-database-entry/page/2/#findComment-828076 Share on other sites More sharing options...
HokieTracks Posted May 6, 2009 Author Share Posted May 6, 2009 Wow, even I should have figured that out! But it works now! Thanks so much man. I know I pissed you off to no end with my stupid questions but you have no idea how much I learned because you were patient and didn't just post the code. Link to comment https://forums.phpfreaks.com/topic/156974-solved-moving-to-the-previous-or-next-database-entry/page/2/#findComment-828078 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.