Jump to content

[SOLVED] "while" issues


chris_2001

Recommended Posts

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

Link to comment
Share on other sites

<?
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

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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