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. Quote Link to comment 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']? Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 6, 2009 Share Posted May 6, 2009 Why do you need it? Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 6, 2009 Share Posted May 6, 2009 Well.. you need PHP tags around that. Quote Link to comment 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 ?> Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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> Quote Link to comment 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. Quote Link to comment 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! Quote Link to comment 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> Quote Link to comment 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. Quote Link to comment 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 ) Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.