Jump to content

Problem wiht my item box script


Xyphon

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";
     }
   }
 }

?>

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');
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.