Woodburn2006 Posted August 10, 2006 Share Posted August 10, 2006 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 methis 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? Quote Link to comment Share on other sites More sharing options...
AndyB Posted August 10, 2006 Share Posted August 10, 2006 [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. Quote Link to comment Share on other sites More sharing options...
Woodburn2006 Posted August 11, 2006 Author Share Posted August 11, 2006 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' 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.