Jump to content

moving through results (doing my head in)


Woodburn2006

Recommended Posts

i have been trying to figure this out and i just cant crack it. i want to display one result per page and be able to move through the rest of them in the form of a prev and next button. i have received help of this before and somebody gave me a block of code, but i cannot seem to get it sorted, its really annoying me

this is what i use

[code]
<?php

// Select all the records

$qry = "SELECT * FROM `gallery`";
$qry = mysql_query($qry);

// create an array of all the results.
// the keys of this array will be the same as the table fields...
$results = array();
while ($row = mysql_fetch_assoc($qry))
{
foreach($row as $key => $val)
{
  $results[$key][] = $val;
}
}

// grab the record you are looking for (id=18)
$curr = array_keys($results['id'], $id);
$curr = $curr[0]; // array_keys returns an array - even if only one result!

$prev = $curr - 1;
$next = $curr + 1;

$name = $results['name'][$id];
$img = $results['img'][$id];
$status = $results['status'][$id];
$price = $results['price'][$id];
$height = $results['height'][$id];
$width = $results['width'][$id];
$description = $results['description'][$id];

echo $name;

echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?id=" . $prev . "\">previous</a>";
echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?id=" . $next . "\">next</a>";

?>
[/code]

does anybody know what i am doing wrong?
Link to comment
Share on other sites

[quote]does anybody know what i am doing wrong?[/quote]

Guess #1: not connecting to the database?
Guess #2: not retrieving the id passed by URL form the $_GET array?
Guess #3: ignoring the cases where next and/or previous don't exist?

I don't know. Why don't you explain what is happening that makes you think it's worng.
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.