Jump to content

Archived

This topic is now archived and is closed to further replies.

Woodburn2006

moving through results (doing my head in)

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?

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
it is connecting to the database as it is getting results, the next and prev buttons dont work, they are just the same value as the record currently viewed.

also, when i echo a variable to be shown all it says is 'Array'

Share this post


Link to post
Share on other sites

×

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.