- 0
(PHP) POST'ing values from a table with checkboxes?
-
Recently Browsing 0 members
- No registered users viewing this page.
-
Posts
-
By cleverclogs · Posted
It's the only reason I finally have an iPhone (for work) and enjoy using it so much that I'm tempted to move from android next time I need to replace my own device -
By leonsk29 · Posted
So is Russia, China, Iran, North Korea, just to mention a few. What's your point? Everyone is a threat from their enemies' perspective. I'd say that Israel is only a threat to their immediate enemies like Hamas, Hezbollah and the Iranian regime, not to anyone else. -
By astropheed · Posted
The government is not the good guy either. You propose 99% of people require that the government overreach and govern their freedom of information and privacy, while ignoring the government is made up 100% of people, of which 99% are (as you described) brain dead. You can't have both. The reality is Signal is absolutely right and the government is doing what it has always done. Ignoring that we are their boss and grabbing all the power they possibly can to make sure we aren't. Your (societies) ###### parenting is not reason enough as to why I can't have a safe platform for my data/information. Thinking the government is helping is precisely what they are targeting psychologically to take suckers like you for a ride. "Think of the children" was, has, is, and will always be a mechanism of control. In the rare occasion it's actually essential the mass consensus has always been there and it doesn't become a debate. -
By AsherGZ · Posted
Israel is a threat to the world. -
By Copernic · Posted
Google Chrome 149.0.7827.103 (offline installer) by Razvan Serea The web browser is arguably the most important piece of software on your computer. You spend much of your time online inside a browser: when you search, chat, email, shop, bank, read the news, and watch videos online, you often do all this using a browser. Google Chrome is a browser that combines a minimal design with sophisticated technology to make the web faster, safer, and easier. Use one box for everything--type in the address bar and get suggestions for both search and Web pages. Thumbnails of your top sites let you access your favorite pages instantly with lightning speed from any new tab. Desktop shortcuts allow you to launch your favorite Web apps straight from your desktop. Chrome has many useful features built in, including automatic full-page translation and access to thousands of apps, extensions, and themes from the Chrome Web Store. Google Chrome is one of the best solutions for Internet browsing giving you high level of security, speed and great features. Important to know! The offline installer links do not include the automatic update feature. Download web installer: Google Chrome Web 32-bit | Google Chrome 64-bit | Freeware Download: Google Chrome Offline Installer 64-bit | Direct Link | 131.0 MB Download: Google Chrome Offline Installer 32-bit | Direct Link | 119.0 MB Download page: Google Chrome Portable Download: Chrome ARM64 | Direct Link View: Chrome Website | Release Notes Get alerted to all of our Software updates on Twitter at @NeowinSoftware
-
-
Recent Achievements
-
Captain_Eric earned a badge
Very Popular
-
amusc earned a badge
One Month Later
-
DJC50PLUS earned a badge
One Month Later
-
DJC50PLUS earned a badge
Week One Done
-
Eric Biran went up a rank
Proficient
-
-
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