Jump to content

Why aren't these whiles working?


almightyegg

Recommended Posts

I've done 3 whiles that while the same content but pick out different parts but only the first one is working...

$select = mysql_query("SELECT * FROM itemsowned WHERE userid = '{$mem['id']}'");
$howmany = mysql_num_rows($select);
if($howmany == 0){
echo "You have no items.<br>";
}else{

echo "Alchemy<br>";
while($item = mysql_fetch_array($select)){
$details = mysql_fetch_array(mysql_query("SELECT * FROM items WHERE code = '{$item['code']}'"));
$amount = number_format($item[amount]);
	if($details[section] == 1){
		if($details[sell] == No){
echo "$details[name] ($amount)<br>";
		}else{
echo "<a href='market/market.php?code=$item[code]&sort=$mem[sortmarket]'>$details[name]</a> ($amount)<br>";
		}
	}
}

echo "Materials<br>";
while($item = mysql_fetch_array($select)){
$details = mysql_fetch_array(mysql_query("SELECT * FROM items WHERE code = '{$item['code']}'"));
$amount = number_format($item[amount]);
	if($details[section] == 2){
		if($details[sell] == No){
echo "$details[name] ($amount)<br>";
		}else{
echo "<a href='market/market.php?code=$item[code]&sort=$mem[sortmarket]'>$details[name]</a> ($amount)<br>";
		}
	}
}

echo "Pit Items<br>";
while($item = mysql_fetch_array($select)){
$details = mysql_fetch_array(mysql_query("SELECT * FROM items WHERE code = '{$item['code']}'"));
$amount = number_format($item[amount]);
	if($details[section] == 3){
		if($details[sell] == No){
echo "$details[name] ($amount)<br>";
		}else{
echo "<a href='market/market.php?code=$item[code]&sort=$mem[sortmarket]'>$details[name]</a> ($amount)<br>";
		}
	}
}
}

 

It echos out the right stuff rom first while then the other 2 don't send anything out[/code][/code][/code]

Link to comment
https://forums.phpfreaks.com/topic/108235-why-arent-these-whiles-working/
Share on other sites

I changed that and it comes up with:

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/lordofth/public_html/house.php on line 252

 

line 252:

echo "<a href='market/market.php?code=$item

&sort=$mem[sortmarket]'>$details[name]</a> ($amount)<br>";

I tried changing that to this:
echo "<a href=\"market/market.php?code=$item['code']&sort=$mem['sortmarket']\">$details['name']</a> ($amount)<br>";

But no joy

I don't know what I changed but the error has now gone. Still showing wrong info...

$select = mysql_query("SELECT * FROM itemsowned WHERE userid = '{$mem['id']}'");
$howmany = mysql_num_rows($select);
if($howmany == 0){
echo "You have no items.<br>";
}else{

echo "Alchemy<br>";
while($item = mysql_fetch_array($select)){
$details = mysql_fetch_array(mysql_query("SELECT * FROM items WHERE code = '{$item['code']}'"));
$amount = number_format($item[amount]);
	if($details['section'] == '1'){
		if($details['sell'] == 'No'){
echo " $details[name] ($amount)<br>";
		}else{
echo " <a href='market/market.php?code={$item['code']}&sort={$mem['sortmarket']}'>{$details['name']}</a> ($amount)<br>";
		}
	}
}

echo "Materials<br>";
while($item = mysql_fetch_array($select)){
$details = mysql_fetch_array(mysql_query("SELECT * FROM items WHERE code = '{$item['code']}'"));
$amount = number_format($item[amount]);
	if($details['section'] == '2'){
		if($details['sell'] == 'No'){
echo " $details[name] ($amount)<br>";
		}else{
echo " <a href='market/market.php?code={$item['code']}&sort={$mem['sortmarket']}'>{$details['name']}</a> ($amount)<br>";
		}
	}
}

echo "Pit Items<br>";
while($item = mysql_fetch_array($select)){
$details = mysql_fetch_array(mysql_query("SELECT * FROM items WHERE code = '{$item['code']}'"));
$amount = number_format($item[amount]);
	if($details['section'] == '3'){
		if($details['sell'] == 'No'){
echo " $details[name] ($amount)<br>";
		}else{
echo " <a href='market/market.php?code={$item['code']}&sort={$mem['sortmarket']}'>{$details['name']}</a> ($amount)<br>";
		}
	}
}
}

 

This echos:

Inventory

Alchemy

Blah (1)

Blah (87)

Blah(1,000)

Blah (10)

Blah (119)

Blah (2)

Materials

Pit Items

 

 

And there are definitely things that sould show up in materials and pit items....

I might have miss understood what BlueSkyIS said then...

 

you should have ALL strings quoted. not only 'No' in your if's but also your array indexes, $details['section'], etc.

 

No != 'No'

 

I changed that ....

 

Not if what you just posted is your current code.

 

What havn't I done? Or what have I done wrong?

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.