Xyphon Posted June 25, 2008 Share Posted June 25, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/111941-problem-wiht-my-item-box-script/ Share on other sites More sharing options...
ionik Posted June 26, 2008 Share Posted June 26, 2008 you need to loop through the results and then perfrom all the neccessary scripting in each loop while($Rows1 = mysql_fetch_array($Result1)) { ///etc } while($Rows2 = mysql_fetch_array($Result2)) { ///etc } Quote Link to comment https://forums.phpfreaks.com/topic/111941-problem-wiht-my-item-box-script/#findComment-574533 Share on other sites More sharing options...
trq Posted June 26, 2008 Share Posted June 26, 2008 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"; } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/111941-problem-wiht-my-item-box-script/#findComment-574534 Share on other sites More sharing options...
Xyphon Posted June 26, 2008 Author Share Posted June 26, 2008 Can you explain exactly where to put it? Quote Link to comment https://forums.phpfreaks.com/topic/111941-problem-wiht-my-item-box-script/#findComment-574535 Share on other sites More sharing options...
DarkWater Posted June 26, 2008 Share Posted June 26, 2008 Also, you can easily fake cookie by just adding them to your browser...so you might want to use sessions. Quote Link to comment https://forums.phpfreaks.com/topic/111941-problem-wiht-my-item-box-script/#findComment-574570 Share on other sites More sharing options...
Xyphon Posted June 26, 2008 Author Share Posted June 26, 2008 I guess so, but meh. I need help on where to put the while. Quote Link to comment https://forums.phpfreaks.com/topic/111941-problem-wiht-my-item-box-script/#findComment-574572 Share on other sites More sharing options...
DarkWater Posted June 26, 2008 Share Posted June 26, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/111941-problem-wiht-my-item-box-script/#findComment-574576 Share on other sites More sharing options...
Xyphon Posted June 26, 2008 Author Share Posted June 26, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/111941-problem-wiht-my-item-box-script/#findComment-574577 Share on other sites More sharing options...
Shiny_Charizard Posted June 26, 2008 Share Posted June 26, 2008 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'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/111941-problem-wiht-my-item-box-script/#findComment-574703 Share on other sites More sharing options...
Xyphon Posted June 26, 2008 Author Share Posted June 26, 2008 That doesn't desplay anything except Weapons:... Basically, it's not executing the "While" Script. Quote Link to comment https://forums.phpfreaks.com/topic/111941-problem-wiht-my-item-box-script/#findComment-574779 Share on other sites More sharing options...
Shiny_Charizard Posted June 26, 2008 Share Posted June 26, 2008 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'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/111941-problem-wiht-my-item-box-script/#findComment-575124 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.