Xyphon Posted June 26, 2008 Share Posted June 26, 2008 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 More sharing options...
rhodesa Posted June 26, 2008 Share Posted June 26, 2008 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'); ?> Link to comment https://forums.phpfreaks.com/topic/112038-solved-problem-with-while-statement/#findComment-575095 Share on other sites More sharing options...
Xyphon Posted June 26, 2008 Author Share Posted June 26, 2008 Now I have another issue. When they switch slots, it turns every item with your ID to the item switched name, with a ' at the end. Link to comment https://forums.phpfreaks.com/topic/112038-solved-problem-with-while-statement/#findComment-575098 Share on other sites More sharing options...
rhodesa Posted June 26, 2008 Share Posted June 26, 2008 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'"); Link to comment https://forums.phpfreaks.com/topic/112038-solved-problem-with-while-statement/#findComment-575105 Share on other sites More sharing options...
Xyphon Posted June 26, 2008 Author Share Posted June 26, 2008 Lol I didn't even notice that, thanks. Link to comment https://forums.phpfreaks.com/topic/112038-solved-problem-with-while-statement/#findComment-575108 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.