chris_2001 Posted August 6, 2008 Share Posted August 6, 2008 When I execute this code I get the echo (echo "Order Status: $StatusName" for the lowest ID repeating over and over. This is evedently an issue with the while statement but I can't seem to pinpoint it. Thanks for the help $sql="SELECT OrderNum FROM orders WHERE ID = '".$ID."'"; $result=mysql_query($sql); while (mysql_fetch_row($result)) { $query = "SELECT OrderNum, Status, OrderStam, OrderAgil, OrderSpellDmg, OrderHeal, OrderScrollAgil, OrderScrollStr, OrderStamBad FROM orders WHERE ID = '".$ID."'"; $result = mysql_query($query); $row = mysql_fetch_array($result, MYSQL_ASSOC); $Status = $row['Status']; $OrderStam = $row['OrderStam']; $OrderAgil = $row['OrderAgil']; if ($Status != 6) { if ($Status == 2) { $StatusName = "ot yet in stock."; } if ($Status == 3) { $StausName = "Order in stock."; } if ($Status == 4) { $StatusName = "Order mailed."; } if ($Status == 5) { $StatusName = "Order completed. Thanks for purchasing!"; } echo "Order Status: $StatusName"; Quote Link to comment Share on other sites More sharing options...
chris_2001 Posted August 6, 2008 Author Share Posted August 6, 2008 anyone?? Quote Link to comment Share on other sites More sharing options...
btherl Posted August 6, 2008 Share Posted August 6, 2008 You are re-using the $result variable inside the while loop. Quote Link to comment Share on other sites More sharing options...
chris_2001 Posted August 6, 2008 Author Share Posted August 6, 2008 Thanks now it is returning the same $Status value for each different instance of each order though :/ any help with that? haha Quote Link to comment Share on other sites More sharing options...
chris_2001 Posted August 6, 2008 Author Share Posted August 6, 2008 It is probably something obvious again I just don't see it :/ Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted August 6, 2008 Share Posted August 6, 2008 your name naming the array here. while (mysql_fetch_row($result)) { change it to... while ($myrow = mysql_fetch_array($result)) { Quote Link to comment Share on other sites More sharing options...
chris_2001 Posted August 6, 2008 Author Share Posted August 6, 2008 didnt do anything, still treats both the "orders" the same and returns the same values for each as if they were identical Quote Link to comment Share on other sites More sharing options...
btherl Posted August 6, 2008 Share Posted August 6, 2008 Can you post your current code with the modifications? Quote Link to comment Share on other sites More sharing options...
chris_2001 Posted August 6, 2008 Author Share Posted August 6, 2008 <? session_start(); if(!session_is_registered(myusername)){ header("location:index.php"); } else{ include "getinfo2.php"; $r = 'Welcome '.$_SESSION["myusername"].'! <A href="logout.php">Logout</a> <br><br> Order limit: '.$Limit.' <br><br>'; echo $r; $sql="SELECT * FROM orders WHERE ID = '".$ID."'"; $result=mysql_query($sql); $count=mysql_num_rows($result); echo "<br>Total orders: $count<br><br>"; if($count==0) { echo "None."; } else { $sql="SELECT OrderNum FROM orders WHERE ID = '".$ID."'"; $result=mysql_query($sql); while ($myrow = mysql_fetch_array($result)) { $query = "SELECT OrderNum, Status, OrderStam, OrderAgil, OrderSpellDmg, OrderHeal, OrderScrollAgil, OrderScrollStr, OrderStamBad FROM orders WHERE ID = '".$ID."'"; $result2 = mysql_query($query); $row = mysql_fetch_array($result2, MYSQL_ASSOC); $OrderNum = $row['OrderNum']; $Status = $row['Status']; $OrderStam = $row['OrderStam']; $OrderAgil = $row['OrderAgil']; $OrderSpellDmg = $row['OrderSpellDmg']; $OrderHeal = $row['OrderHeal']; $OrderScrollAgil = $row['OrderScrollAgil']; $OrderScrollStr = $row['OrderScrollStr']; $OrderStamBad = $row['OrderStamBad']; if ($Status != 6) { if ($Status == 2) { $StatusName = "Not yet in stock."; } if ($Status == 3) { $StausName = "Order in stock."; } if ($Status == 4) { $StatusName = "Order mailed."; } if ($Status == 5) { $StatusName = 'Order paid for and completed. Thanks for purchasing!<form name="form1" method="post" action="remove.php"> <input name="RemoveOrderNum" type="hidden" id="RemoveOrderNum" value='.$OrderNum.'><input type="submit" id='.$OrderNum.' value="Remove Order" name="Remove"></form>'; } echo "<b>Order Status: $StatusName</b>"; if ($OrderStam != 0) { echo "$NameStamShort: $OrderStam <br>"; } if ($OrderAgil != 0) { echo "$NameAgilShort: $OrderAgil <br>"; } if ($OrderSpellDmg != 0) { echo "$NameSpellDmgShort: $OrderSpellDmg <br>"; } if ($OrderHeal != 0) { echo "$NameHealShort: $OrderHeal <br>"; } if ($OrderStamBad != 0) { echo "$NameStamBadShort: $OrderStamBad <br>"; } if ($OrderScrollAgil != 0) { echo "$NameScrollAgilShort: $OrderScrollAgil <br>"; } if ($OrderScrollStr != 0) { echo "$NameScrollStrShort: $OrderScrollStr <br>"; } echo "<BR><BR><BR><BR>"; } } } } Here ya go - posted the whole thing this time. Thanks for all the help by the way Quote Link to comment Share on other sites More sharing options...
dilum Posted August 6, 2008 Share Posted August 6, 2008 what is here "$ID" value ? seems it is not change whithin while loop. Therefore every time fetch result inside the while loop is same. Quote Link to comment Share on other sites More sharing options...
chris_2001 Posted August 6, 2008 Author Share Posted August 6, 2008 $ID is the account ID and so will not change. What does change is $OrderNum Quote Link to comment Share on other sites More sharing options...
chris_2001 Posted August 6, 2008 Author Share Posted August 6, 2008 anyone have any ideas why? Quote Link to comment Share on other sites More sharing options...
btherl Posted August 6, 2008 Share Posted August 6, 2008 I think you need this query: $query = "SELECT OrderNum, Status, OrderStam, OrderAgil, OrderSpellDmg, OrderHeal, OrderScrollAgil, OrderScrollStr, OrderStamBad FROM orders WHERE ID = '".$ID."' AND OrderNum = '".$myrow['OrderNum']."'"; Doesn't it strike you as odd that you never use $myrow? Actually you could simplify it all by making that query above your query for the while loop itself. But for now I would get it working as it is first. All of it can be done in a single query (the counting, the looping and the fetching of data). Quote Link to comment Share on other sites More sharing options...
chris_2001 Posted August 6, 2008 Author Share Posted August 6, 2008 haha ur right i didnt use it yeah that worked thanks for the help now I have another problem that it treats $OrderNum the same for all of them but all the other data is right so it should be easy to fix Quote Link to comment Share on other sites More sharing options...
chris_2001 Posted August 6, 2008 Author Share Posted August 6, 2008 Finally fixed it Now im going to make it one query like you said to haha thanks for the help Quote Link to comment 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.