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
Share on other sites

Yeah I'm aware of that. But I've made it so that if the item isn't in their shop the script dies before the do statement is executed.

 

EDIT: Anyways, thanks for your opinion. I am pretty sure it's gunna do what I need it to do. Topic Solved :P!

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.