Forum Moderators: coopster

Message Too Old, No Replies

Variable list

only showing one variable

         

NogginAnimations

8:59 am on Jan 25, 2008 (gmt 0)

10+ Year Member



So I'm making a page for my users to buy stuff with, and this is the list of things that they have.
I'm pretty sure the code is good, but it keeps giving me only one table row instead of the 5 that exist in the database.
Why is this?
Here is my code:

...rname = $_SESSION['username'];
$result2 = mysql_query("SELECT * FROM userbought WHERE username='$username' ") or die(mysql_error());
while($r2 = mysql_fetch_array($result2)) { $btname = $r2['item']; }
$result3 = mysql_query("SELECT * FROM items WHERE name='$btname' ORDER BY id ASC") or die(mysql_error());
while($r3 = mysql_fetch_array($result3)) {
$id = $r3['id'];
$name = $r3['name'];
$icon = $r3['icon'];
$desc = $r3['desc'];
$cost = $r3['cost'];
$icon = str_replace("[img-locker]","",$icon);
$icon = str_replace("[image]","<img src='",$icon);
$icon = str_replace("[/image]","' border='0' width='16' height='16' style='cursor:pointer;' />",$icon);
$num == 0;
if ($num & 1)
{
$num += 1;?>
<tr sty...

EDIT:
I fixed the problem by changing the code verrry slightly.
I have edited the codes to show what I changed.

...rname = $_SESSION['username'];
$result2 = mysql_query("SELECT * FROM userbought WHERE username='$username' ") or die(mysql_error());
while($r2 = mysql_fetch_array($result2)) { $btname = $r2['item'];
$result3 = mysql_query("SELECT * FROM items WHERE name='$btname' ORDER BY id ASC") or die(mysql_error());
while($r3 = mysql_fetch_array($result3)) {
$id = $r3['id'];
$name = $r3['name'];
$icon = $r3['icon'];
$desc = $r3['desc'];
$cost = $r3['cost'];
$icon = str_replace("[img-locker]","",$icon);
$icon = str_replace("[image]","<img src='",$icon);
$icon = str_replace("[/image]","' border='0' width='16' height='16' style='cursor:pointer;' />",$icon); }
$num == 0;
if ($num & 1)
{
$num += 1;?>
<tr sty...

[edited by: NogginAnimations at 9:07 am (utc) on Jan. 25, 2008]

jatar_k

12:59 pm on Jan 25, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



nice

of course by closing the first while loop you couldn't loop through the results from the first query properly