DJTim666 Posted August 29, 2007 Share Posted August 29, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/67232-solved-need-help/ Share on other sites More sharing options...
piznac Posted August 29, 2007 Share Posted August 29, 2007 It looks good to me,... Do{ }while will run the statement once even if the while is not true. Quote Link to comment https://forums.phpfreaks.com/topic/67232-solved-need-help/#findComment-337238 Share on other sites More sharing options...
DJTim666 Posted August 29, 2007 Author Share Posted August 29, 2007 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 ! Quote Link to comment https://forums.phpfreaks.com/topic/67232-solved-need-help/#findComment-337243 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.