Jump to content


Photo

moving through results (doing my head in)


  • Please log in to reply
2 replies to this topic

#1 Woodburn2006

Woodburn2006
  • Members
  • PipPipPip
  • Advanced Member
  • 214 posts

Posted 10 August 2006 - 08:21 PM

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

<?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>";

?>

does anybody know what i am doing wrong?

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 10 August 2006 - 09:23 PM

does anybody know what i am doing wrong?


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.
Legend has it that reading the manual never killed anyone.
My site

#3 Woodburn2006

Woodburn2006
  • Members
  • PipPipPip
  • Advanced Member
  • 214 posts

Posted 11 August 2006 - 06:36 PM

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'




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users