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
https://forums.phpfreaks.com/topic/118378-solved-quotwhilequot-issues/
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

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

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.