- 0
(PHP) POST'ing values from a table with checkboxes?
-
Recently Browsing 0 members
- No registered users viewing this page.
-
Posts
-
By +TRS-80 · Posted
I gave up on browser ad-blocking extensions a few years ago, replaced them with Adguard. Not perfect but overhaul is a nice app that does the job on both Windows and Android with the respective versions. -
By Copernic · Posted
Glary Utilities 6.43.0.47 by Razvan Serea Glary Utilities offers numerous powerful and easy-to-use system tools and utilities to fix, speed up, maintain and protect your PC. Glary Utilities allow you to clean common system junk files, as well as invalid registry entries and Internet traces. You can manage and delete browser add-ons, analyze disk space usage and find duplicate files. You can also view and manage installed shell extensions, encrypt your files from unauthorized access and use, split large files into smaller manageable files and then rejoin them. Furthermore, Glary Utilities includes the options to find, fix, or remove broken Windows shortcuts, manage the programs that start at Windows startup and uninstall software. All Glary Utilities tools can be accessed through an eye-pleasing and totally simplistic interface. Glary Utilities 6.43.0.47 changelog: Optimized Memory Defrager: Optimized the clipboard cleaning algorithm, increasing speed by 5%. Optimized Wipe Free Space: Optimized the free space wiping algorithm, increasing speed by 8%. Minor GUI improvements. Minor bug fixes. Download: Glary Utilities 6.43.0.47 | 27.0 MB (Freeware) Download: Portable Glary Utilities | 32.3 MB View: Glary Utilities Homepage | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware -
By +Edouard · Posted
"Of course the easiest solution is to switch to uBlock Origin Lite if you want to remain on Chrome, as it is MV3-based, but from our experience, uBO Lite does not seem to be as good as the original non-Lite version" In my experience uBlock Origin Lite does the job for normal everday home users. When they kill that we get to watch Firefox and Brave get a boost in user market share. -
By TheGhostPhantom · Posted
Block by DNS ad blocker! I dare you! I will even layer unlock Origin, on top of my internal DNS, if I need to and I don’t even block ads today (I really should but this type of behavior makes me angry). I suppose I could also just be lazy, and add the flags myself, back to each release (it wouldn’t be that difficult). -
By ExecutiveFunction404 · Posted
Wonder what MPs have ties to these privacy/verification/data harvesting companies that are going to step in this time. Last time under the Tories half the cabinet had fingers in the pies, heck even the PM and his wife at the time was working for silicon valley, probably made a fortune.
-
-
Recent Achievements
-
skylerssviv earned a badge
Week One Done
-
mobmobiles earned a badge
One Month Later
-
Captain_Eric earned a badge
Very Popular
-
amusc earned a badge
One Month Later
-
DJC50PLUS earned a badge
One Month Later
-
-
Popular Contributors
-
Tell a friend
Question
Bollard
Sorry for the never ending flow of questions, but I have another question, that i was looking for some help for regarding a search stock page that i have been building:
As you can see from the code below, the search query outputs a table. The user first checks a row corresponding to an item they want (the RFQ column) and then one of the columns (called Quantity), in where the user can enter a quantity of the product they want. They then click a button and a request for quotation will be sent to the company (at the moment im just trying to echo out the selections made).
The query and output:
while ($rows = mysql_fetch_array($query)) { echo '<tr>'; echo '<td><input type="checkbox" value="' . $rows['Part Number'] . '" name="RFQ[]"></td>'; echo '<td>' . $rows['Part Number'] . '</td>'; echo '<td>' . $rows['Manufacturer'] . '</td>'; echo '<td>' . $rows['Stock'] . '</td>'; echo '<td><input type="text" value="' . $_POST['Quantity'] . '" name="Quantity[]" tabindex="' . $tabindex++ .'" /></td>'; echo '<td><select name="Delivery" tabindex="' . $tabindex++ .'"> <option value="Any">Any</option> <option value="Emergency">Emergency</option> <option value="Next Day">Next Day</option> <option value="2-3">2-3 Days</option> <option value="4-6">4-6 Days</option> <option value="7-10">7-10 Days</option> <option value="10+">10+ Days</option> </select></td>'; echo '</tr>'; } echo '</table>'; echo $rows; // Send request for quotation echo '<input type="submit" name ="SendRFQ" value="Request Quotation">'; echo '</form>';Which is then displayed:
// Check if parts have been selected for quotation already if (isset($_POST['SendRFQ'])) { $RFQ = $_POST['RFQ']; $Quantity=$_POST['Quantity']; $NumberRFQ = count($RFQ); // List parts selected for quotation if ($NumberRFQ>0) { echo 'RFQs chosen: '.$NumberRFQ.'<br /><br />'; echo 'You chose the following:<br /<br />'; echo '<table border="1" align="center">'; echo '<tr><th>Part Number</th>'; echo "<th>Quantity?</th></tr>"; for ($i=0; $i<$NumberRFQ; $i++) { echo '<tr>'; echo '<td>' . $RFQ[$i] . '</td>'; echo '<td>' . $Quantity[$i] . '</td>'; echo '</tr>'; } echo "</table>"; echo '<br /><br />'; } else { echo 'No parts have been chosen for quotation<br /><br />'; echo '<a href="/search.php">Click here</a> to go back<br /><br />'; } }Which kinda works.
If i select say, the first three rows sequentially, the quantities are displayed correctly.
But say i select rows 1, 3 and 5 (and enter quantities as 1, 3 and 5 respectively), then row 1 shows quantity 1, row 2 shows nothing and row 3 shows quantity 3?!
I understand it is becuase the RFQ[] array only contains the checked part numbers, where as the Quantity[] array contains all the cells contents, so the $i dont match - but i have no idea how to correct this?
Any ideas?
Cheers
Link to comment
https://www.neowin.net/forum/topic/909526-php-posting-values-from-a-table-with-checkboxes/Share on other sites
20 answers to this question
Recommended Posts