Jump to content

[SOLVED] Need help.


DJTim666

Recommended Posts

I want to know if the way I have done my code is correct or not.

 

<?php
if ($act == 'prices')
{
echo "<table border='1' width='100%' bordercolor='blue'>
	<tr>
		<td><b>Item</b></td>
		<td><b>Price</b></td>
		<td><b>Remove</b></td>
	</tr>";
if (!mysql_num_rows($query))
{
	showerror("<tr><td colspan='3'>You don't have any items in your shop.</td></tr></table>");
}
echo "<form action='$PHP_SELF?act=doprices' method='post'>";
$pr = 1;
while ($row_shop = mysql_fetch_array($query))
{
	echo "<tr>
			<td><img src='" . $row_shop['image'] . "'><br />" . $row_shop['name'] . "</td>
			<td><input type='text' size='10' name='price" . $pr . "' value='" . $row_shop['shop_price'] . "' /><br />Low. Price: ....</td>
			<td>[Remove 1]<br />[Remove All]</td>
		</tr>";
	$pr++;
}
echo "<tr><td colspan='3'><input type='submit' value='Change Prices' /></td></tr>";
echo "</from></table>";
}
if ($act == 'doprices')
{
$f = 1;
do {
	$newprice = mysql_fetch_array($query);
	$price = $_POST['price' . $f . ''];
	$arrayit = array($price);
	foreach ($arrayit as $new)
	{
		if ($new == '')
		{
			showerror("You can't update an item with no price.");
		}
		if (!is_numeric($new))
		{
			showerror("You have entered a non-numeric value.");
		}
		mysql_query("UPDATE user_items SET shop_price=" . $new . " WHERE ID=" . $newprice['ID'] . "");
	}
	$f++;
}
while ($f <= mysql_num_rows($query));
}	

require_once("footer.php");
?>

 

This code does exactly what I want it to do. It's just that I haven't seen to many people using do {} while (); statements.

 

--

DJ

Link to comment
https://forums.phpfreaks.com/topic/67232-solved-need-help/
Share on other sites

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.