kdalts Posted January 8, 2011 Share Posted January 8, 2011 Hi folks... I really didn't know how to title this thread so I hope it makes sense Here is what I am trying to do: Create an editable list of items, price and stock using the 'while' loop - this I can easily do like this... echo "<table width=\"100%\" cellspacing=0>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td width=40% class=item_list>$row[mbp_name]</td>"; echo "<td align=right width=20% class=item_list>"; echo "<input value=\"$row[mbp_price]\" size=\"2\" maxlength=\"5\" type=\"text\" name=\"mbp_price\" /></td>"; echo "<td align=right width=20% class=item_list>"; echo "<input value=\"$row[mbp_stock]\" size=\"2\" maxlength=\"5\" type=\"text\" name=\"mbp_stock\" /></td>"; echo "<td align=right width=20% class=item_list>" . $row['mbp_stock']*$row['mbp_price'] . "</td>"; echo "</tr>"; } echo "</tr></table>"; If I have the update outside the loop then there are only 3 fields that contain a value after the loop is completed ie: mbp_item = the last record name of the table, mbp_price=the last record price and mbp=the last record stock. If I have the update inside the loop the table will update each record but the user may decide to cancel - so then the data in the table is wrong. As an extra feature, I would also be inetersted to know the best way to check that an entered value is valid before the user moves the cursor to a new field? Does anyone have a clue what the best way to do this please? Quote Link to comment https://forums.phpfreaks.com/topic/223762-while-loop-and-update/ Share on other sites More sharing options...
inversesoft123 Posted January 8, 2011 Share Posted January 8, 2011 for first solution you can use a temporary table to insert records or database triggers. for second solution you can use AJAX to check validity of inputs submitted by users. Quote Link to comment https://forums.phpfreaks.com/topic/223762-while-loop-and-update/#findComment-1156613 Share on other sites More sharing options...
kdalts Posted January 22, 2011 Author Share Posted January 22, 2011 Appreciate your reply but it doesn;t really help me too much being a novice at this... any examples or links you could recommend... thanks Quote Link to comment https://forums.phpfreaks.com/topic/223762-while-loop-and-update/#findComment-1163491 Share on other sites More sharing options...
PFMaBiSmAd Posted January 22, 2011 Share Posted January 22, 2011 Umm. The post by inversesoft123 in this thread must have been intended for some other thread, because it has absolutely nothing to do with your problem. You are reusing the same exact names in each set of similar form fields and the last set of fields in the form using those names will be what is submitted. You should use an array for the field names. See this link - http://us3.php.net/manual/en/faq.html.php#faq.html.arrays Once you do this, you can simply use php array functions, such as foreach(), to iterate over the arrays of data from the form. Quote Link to comment https://forums.phpfreaks.com/topic/223762-while-loop-and-update/#findComment-1163494 Share on other sites More sharing options...
kdalts Posted January 27, 2011 Author Share Posted January 27, 2011 Thanks again... Still too complex for me... any faint hope of a specific snipet based on my code above please? Quote Link to comment https://forums.phpfreaks.com/topic/223762-while-loop-and-update/#findComment-1165896 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.