adamhhh Posted September 4, 2006 Share Posted September 4, 2006 hi guys, im having a few problems returning stuff from a database and this is a problem ive had before and not been able to solve. Basically i retrieve lots of stuff, however it only displays the last item that has been added rather than displaying everything. how do i get it to display everything?? i just cant figure it out!!This is a simple page to show what im trying to achieve, its just returning information regarding products people have added to a mock 'wishlist'.[code]<?phprequire 'incs/php.php';$conx = @mysql_connect("$dbServer", "$dbUser", "$dbPass");@mysql_select_db("$dbName");if (!$conx){ echo ("No Database Access<br />Please try again"); exit;}$result = mysql_query("select * FROM wishlist where login='test'");while($r=mysql_fetch_array($result)){ $id=$r["id"]; $login=$r["login"];}$result2 = mysql_query("select * FROM product where id=$id");while($r=mysql_fetch_array($result2)){ $prodId=$r["id"]; $manuf=$r["manuf"]; $name=$r["name"]; $description=$r["description"]; $size=$r["size"]; $type=$r["type"]; $fibre=$r["fibre"]; $dimensions=$r["dimensions"]; $image=$r["image"]; echo $prodId; echo "<br />"; echo $manuf;echo "<br />"; echo $name;echo "<br />"; echo $description;echo "<br />"; echo $size;echo "<br />"; echo $type;echo "<br />"; echo $fibre;echo "<br />"; echo $dimensions;}?>[/code]any ideas?[b]EDITED BY WILDTEEN88: PLEASE USE [nobbc][CODE][/CODE][/nobbc] OR THE [nobbc][PHP][/PHP][/nobbc] TAGS WHEN POSTING CODE.[/B] Quote Link to comment https://forums.phpfreaks.com/topic/19680-returning-stuff-from-database-confusing/ Share on other sites More sharing options...
wildteen88 Posted September 4, 2006 Share Posted September 4, 2006 You need to add this:[code]$result2 = mysql_query("select * FROM product where id=$id");while($r=mysql_fetch_array($result2)){ $prodId=$r["id"]; $manuf=$r["manuf"]; $name=$r["name"]; $description=$r["description"]; $size=$r["size"]; $type=$r["type"]; $fibre=$r["fibre"]; $dimensions=$r["dimensions"]; $image=$r["image"]; echo $prodId; echo "<br />"; echo $manuf;echo "<br />"; echo $name;echo "<br />"; echo $description;echo "<br />"; echo $size;echo "<br />"; echo $type;echo "<br />"; echo $fibre;echo "<br />"; echo $dimensions;}[/code] Into your first while loop, otherwise it'll just retrun the last result from the first query.This should do:[code]<?phprequire 'incs/php.php';$conx = @mysql_connect($dbServer, $dbUser, $dbPass);@mysql_select_db($dbName) or die("No Database Access<br />Please try again");$result = mysql_query("select * FROM wishlist where login='test'");while($r = mysql_fetch_array($result)){ $id = $r["id"]; $login = $r["login"]; $result2 = mysql_query("select * FROM product where id=$id"); $rp = mysql_fetch_array($result2)) $prodId = $rp["id"]; $manuf = $rp["manuf"]; $name = $rp["name"]; $description = $rp["description"]; $size = $rp["size"]; $type = $rp["type"]; $fibre = $rp["fibre"]; $dimensions = $rp["dimensions"]; $image = $rp["image"]; echo $prodId . "<br />\n"; echo $manuf . "<br />\n"; echo $name . "<br />\n"; echo $description . "<br />\n"; echo $size . "<br />\n"; echo $type . "<br />\n"; echo $fibre . "<br />\n"; echo $dimensions; echo "<br /><br />";}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/19680-returning-stuff-from-database-confusing/#findComment-85800 Share on other sites More sharing options...
adamhhh Posted September 4, 2006 Author Share Posted September 4, 2006 $rp?? Quote Link to comment https://forums.phpfreaks.com/topic/19680-returning-stuff-from-database-confusing/#findComment-85813 Share on other sites More sharing options...
AndyB Posted September 4, 2006 Share Posted September 4, 2006 [quote author=adamhhh link=topic=106853.msg427829#msg427829 date=1157385836]$rp??[/quote]It's just the name of an array. It could have been almost anything and wouldn't affect the code. Quote Link to comment https://forums.phpfreaks.com/topic/19680-returning-stuff-from-database-confusing/#findComment-85817 Share on other sites More sharing options...
wildteen88 Posted September 4, 2006 Share Posted September 4, 2006 I used $rp because if I used $r for retriving the results from the secound query, it would of overwirte the first set of results, which will result in your script not working correctly. Quote Link to comment https://forums.phpfreaks.com/topic/19680-returning-stuff-from-database-confusing/#findComment-85819 Share on other sites More sharing options...
adamhhh Posted September 4, 2006 Author Share Posted September 4, 2006 never mind it all works now :) bit of playing about with braces :P Quote Link to comment https://forums.phpfreaks.com/topic/19680-returning-stuff-from-database-confusing/#findComment-85820 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.