Jump to content

returning stuff from database confusing


adamhhh

Recommended Posts

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]<?php

require '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]
Link to comment
Share on other sites

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]<?php

require '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]
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.