Jump to content

[SOLVED] Problem with while statement!


Xyphon

Recommended Posts

When I use while, it won't loop..

 

Here's my code

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

 

Help please!

Link to comment
https://forums.phpfreaks.com/topic/112038-solved-problem-with-while-statement/
Share on other sites

try this out:

 

<?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);
if(isset($_GET['Choice']))
{
if($_GET['Choice']=="Weapon")
{
mysql_query("UPDATE users SET Weapon='{$_GET['Name']}' WHERE ID='$ID'");
mysql_query("UPDATE item_box SET Type='Weapon', Item_Name='{$_GET['Name']}' 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');
?>

first, to get rid of the ' at the end, update this:

echo "<a href=itemboxweapons.php?Choice=Weapon&Name=$Name'>$Name<br></a>";

to this:

echo "<a href=\"itemboxweapons.php?Choice=Weapon&Name=$Name\">$Name<br></a>";

 

as for the problem of it updating everything, what is the purpose of this line:

mysql_query("UPDATE item_box SET Type='Weapon', Item_Name='{$_GET['Name']}' WHERE Owner_ID='$ID'");

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.