Jump to content

Recommended Posts

This is the script:

<?PHP
include('Connect.php');
include('top.php');
$ID= $_COOKIE['UserID'];
if(!isset($ID))
{
echo "Sorry, you must be logged in to view this page";
include('bottom.php');
exit;
}
$Result1 = mysql_query("SELECT * FROM users WHERE ID='$ID'");
$Rows1 = mysql_fetch_array($Result1);
$Result2 = mysql_query("SELECT * FROM item_box WHERE Owner_ID='$ID'");
$Rows2 = mysql_fetch_array($Result2);
$Name = $Rows2['Item_Name'];
$Name1 = $Rows1['Weapon'];
$Type = $Rows2['Type'];
$Choice = $_GET['Choice'];
if(isset($Choice))
{
if($Choice=="Weapon")
{
mysql_query("UPDATE users SET Weapon='$Name' WHERE ID='$ID'");
mysql_query("UPDATE item_box SET Type='Weapon', Item_Name='$Name1' WHERE Owner_ID='$ID'");
echo "Item equipped! <a href='itembox.php'>Continue?</a>";
}
}
else
{

echo "<b>Weapons:</b><br>";
if($Type=="Weapon")
{
echo "<a href=itemboxweapons.php?Choice=Weapon&Name=$Name'>$Name<br></a>";
}
}
include('bottom.php');
?>

 

Why does it only display the first box item you have in the box?

Link to comment
https://forums.phpfreaks.com/topic/111941-problem-wiht-my-item-box-script/
Share on other sites

Because you only ever call mysql_fetch_array once, if you want to display multiple rows you need to loop through your result resource. The basic syntax is...

 

<?php

 if ($result = mysql_query("SELECT foo FROM bar")) {
   if (mysql_num_rows($result)) {
     while ($row = mysql_fetch_assoc($result)) {
       echo $row['foo']."\n";
     }
   }
 }

?>

while ($row = mysql_fetch_assoc($Results2)) {

  //do some stuff with $row, which contains that rows info in an associative AND numerically indexed array

}

 

That should go around the part where you actually do something with $Results2's data

That doens't help, I tried that and edited it to

 

<?PHP
include('Connect.php');
include('top.php');
$ID= $_COOKIE['UserID'];
if(!isset($ID))
{
echo "Sorry, you must be logged in to view this page";
include('bottom.php');
exit;
}
$Result1 = mysql_query("SELECT * FROM users WHERE ID='$ID'");
$Rows1 = mysql_fetch_array($Result1);
$Result2 = mysql_query("SELECT * FROM item_box WHERE Owner_ID='$ID'");
$Rows2 = mysql_fetch_array($Result2);
$Name = $Rows2['Item_Name'];
$Name1 = $Rows1['Weapon'];
$Type = $Rows2['Type'];
$Choice = $_GET['Choice'];
if(isset($Choice))
{
if($Choice=="Weapon")
{
mysql_query("UPDATE users SET Weapon='$Name' WHERE ID='$ID'");
mysql_query("UPDATE item_box SET Type='Weapon', Item_Name='$Name1' WHERE Owner_ID='$ID'");
echo "Item equipped! <a href='itembox.php'>Continue?</a>";
}
}
else
{

echo "<b>Weapons:</b><br>";
while($Rows2 = mysql_fetch_array($Result2))
{
if($Type=="Weapon")
{
echo "<a href=itemboxweapons.php?Choice=Weapon&Name=$Name'>$Name<br></a>";
}
}
}
include('bottom.php');
?>

 

Wont work.

Try this:

 

<?php
include('Connect.php');
include('top.php');
$ID= $_COOKIE['UserID'];
if(!isset($ID))
{
echo "Sorry, you must be logged in to view this page";
include('bottom.php');
exit;
}
$Result1 = mysql_query("SELECT * FROM users WHERE ID='$ID'");
$Rows1 = mysql_fetch_array($Result1);
$Result2 = mysql_query("SELECT * FROM item_box WHERE Owner_ID='$ID'");
$Name = $Rows2['Item_Name'];
$Name1 = $Rows1['Weapon'];
$Type = $Rows2['Type'];
$Choice = $_GET['Choice'];
if(isset($Choice))
{
if($Choice=="Weapon")
{
mysql_query("UPDATE users SET Weapon='$Name' WHERE ID='$ID'");
mysql_query("UPDATE item_box SET Type='Weapon', Item_Name='$Name1' WHERE Owner_ID='$ID'");
echo "Item equipped! <a href='itembox.php'>Continue?</a>";
}
}
else
{

echo "<b>Weapons:</b><br>";
while($Rows2 = mysql_fetch_array($Result2))
{
if($Type=="Weapon")
{
echo "<a href=itemboxweapons.php?Choice=Weapon&Name=$Name'>$Name<br></a>";
}
}
}
include('bottom.php');
?>

Maybe it's because you don't have the Variables "Name" & "Type" inside the "While" script.

Try this now:

<?php
include('Connect.php');
include('top.php');
$ID= $_COOKIE['UserID'];
if(!isset($ID))
{
echo "Sorry, you must be logged in to view this page";
include('bottom.php');
exit;
}
$Result1 = mysql_query("SELECT * FROM users WHERE ID='$ID'");
$Rows1 = mysql_fetch_array($Result1);
$Name1 = $Rows1['Weapon'];
$Choice = $_GET['Choice'];
$Name = $Rows2['Item_Name'];
if(isset($Choice))
{
if($Choice=="Weapon")
{
mysql_query("UPDATE users SET Weapon='$Name' WHERE ID='$ID'");
mysql_query("UPDATE item_box SET Type='Weapon', Item_Name='$Name1' WHERE Owner_ID='$ID'");
echo "Item equipped! <a href='itembox.php'>Continue?</a>";
}
}
else
{

echo "<b>Weapons:</b><br>";
$Result2 = mysql_query("SELECT * FROM item_box WHERE Owner_ID='$ID'");
while($Rows2 = mysql_fetch_array($Result2))
{
$Name = $Rows2['Item_Name'];
$Type = $Rows2['Type'];
if($Type=="Weapon")
{
echo "<a href=itemboxweapons.php?Choice=Weapon&Name=$Name'>$Name<br></a>";
}
}
}
include('bottom.php');
?>

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.