Jump to content

[SOLVED] Moving to the previous or next database entry


HokieTracks

Recommended Posts

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
Share on other sites

$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
Share on other sites

<?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
Share on other sites

<?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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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  ;D)

Link to comment
Share on other sites

Wow, even I should have figured that out! :D

 

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.