ma5ect Posted November 8, 2008 Share Posted November 8, 2008 hi all. I have a table on my webpage, i want the user to select a check box which is assigned to a field on the table and once the user submits the form, i want that check box data to be displayed on another page... i have got the form with the check box and data field assigned but dont know how i can get it to display onto the next page.. form page code: <form name=orderform action="confirm-order.php"> <table width="648" border="3" align="center"> <tr> <td width="209"><div align="center" class="style12"> <div align="center">Module name</div> </div></td> <td width="120"><div align="center" class="style12"> <div align="center">Module ID</div> </div></td> <td width="158"><div align="center" class="style12"> <div align="center">Credits</div> </div></td> <td width="117"><div align="center" class="style12"> <div align="center">Completed</div> </div></td> <td width="61"><div align="center"></div></td> </tr> <?php do { ?> <tr> <td height="22"><span class="style9"><?php echo $row_Recordset2['Module name']; ?></span></td> <td><div align="center"><?php echo $row_Recordset2['Module ID']; ?></div></td> <td><div align="center"><?php echo $row_Recordset2['credits']; ?></div></td> <td><div align="center"><?php echo $row_Recordset2['Completed']; ?></div></td> <td><input name="module" type="checkbox" id="module" value="<?php echo $row_Recordset2['Module name']; ?>" /></td> </tr> <?php } while ($row_Recordset2 = mysql_fetch_assoc($Recordset2)); ?> </table> <p align="center"> <input type=submit value="Order" /> </form> Quote Link to comment https://forums.phpfreaks.com/topic/131928-displaying-data-on-to-another-page-by-check-box/ Share on other sites More sharing options...
php-pendejo Posted November 8, 2008 Share Posted November 8, 2008 first you put everything in hidden fields like this with in the tags <form> (im guessing this is what you want) <input type=hidden name="whatever" value="<?php echo $row_Recordset2['Module name']; ?>" /> then in the next page or function or what have you you can get the post like $whatever = $_POST['whatever']; let me know if you need anymore explination Quote Link to comment https://forums.phpfreaks.com/topic/131928-displaying-data-on-to-another-page-by-check-box/#findComment-685383 Share on other sites More sharing options...
ma5ect Posted November 8, 2008 Author Share Posted November 8, 2008 the data field does not display onto the output page..its not hidden fields, just the check box value i want displaying Quote Link to comment https://forums.phpfreaks.com/topic/131928-displaying-data-on-to-another-page-by-check-box/#findComment-685422 Share on other sites More sharing options...
solon Posted November 8, 2008 Share Posted November 8, 2008 Where you have: <form name=orderform action="confirm-order.php"> replace it with: <form name="orderform" action="confirm-order.php" method="post"> Quote Link to comment https://forums.phpfreaks.com/topic/131928-displaying-data-on-to-another-page-by-check-box/#findComment-685435 Share on other sites More sharing options...
ma5ect Posted November 8, 2008 Author Share Posted November 8, 2008 the display page just appears blank, i am using <?php $module = $_POST['module']; ?> on this page Quote Link to comment https://forums.phpfreaks.com/topic/131928-displaying-data-on-to-another-page-by-check-box/#findComment-685445 Share on other sites More sharing options...
solon Posted November 8, 2008 Share Posted November 8, 2008 Try this: <form name="orderform" action="confirm-order.php" method="post"> <table width="648" border="3" align="center"> <tr> <td width="209"><div align="center" class="style12"> <div align="center">Module name</div> </div></td> <td width="120"><div align="center" class="style12"> <div align="center">Module ID</div> </div></td> <td width="158"><div align="center" class="style12"> <div align="center">Credits</div> </div></td> <td width="117"><div align="center" class="style12"> <div align="center">Completed</div> </div></td> <td width="61"><div align="center"></div></td> </tr> <?php do { ?> <tr> <td height="22"><span class="style9"><?php echo $row_Recordset2['Module name']; ?></span></td> <td><div align="center"><input type='hidden' name='module' value='<?php echo $row_Recordset2['Module ID']; ?>' /></div></td> <td><div align="center"><?php echo $row_Recordset2['credits']; ?></div></td> <td><div align="center"><?php echo $row_Recordset2['Completed']; ?></div></td> <td><input name="module" type="checkbox" id="module" value="<?php echo $row_Recordset2['Module name']; ?>" /></td> </tr> <?php } while ($row_Recordset2 = mysql_fetch_assoc($Recordset2)); ?> </table> <p align="center"> <input type=submit value="Order" /> </form> I created an input type hidden field named "module" so that $_POST[''] knows from where to get the value! Quote Link to comment https://forums.phpfreaks.com/topic/131928-displaying-data-on-to-another-page-by-check-box/#findComment-685455 Share on other sites More sharing options...
Yesideez Posted November 8, 2008 Share Posted November 8, 2008 As you list your data inside a table have a checkbox defined: <input type="checkbox" name="data" /> Append the unique identifier onto the name of "data" (the name of the checkbox) so you have something like this: <input type="checkbox" name="data1" /> <input type="checkbox" name="data2" /> <input type="checkbox" name="data3" /> <input type="checkbox" name="data4" /> and so-on. When the user selects one or more of the checkboxes and clicks the submit button all you need do is recreate the MySQL call that generated the list and check the names: $query=mysql_query("SELECT data FROM table"); while ($fetch=mysql_fetch_assoc($query)) { if ($_POST['data'.$fetch['id']]) { //checkbox was selected } } Not sure if this is the best way but it works! Quote Link to comment https://forums.phpfreaks.com/topic/131928-displaying-data-on-to-another-page-by-check-box/#findComment-685457 Share on other sites More sharing options...
ma5ect Posted November 8, 2008 Author Share Posted November 8, 2008 the table is created with repeat so i cannot define individual checkboxes. when i run the webpage in the table i get the list of data from database and next to it a check box for each so the user can select Quote Link to comment https://forums.phpfreaks.com/topic/131928-displaying-data-on-to-another-page-by-check-box/#findComment-685473 Share on other sites More sharing options...
Yesideez Posted November 8, 2008 Share Posted November 8, 2008 Can you post the code that shows the data inside the table? Quote Link to comment https://forums.phpfreaks.com/topic/131928-displaying-data-on-to-another-page-by-check-box/#findComment-685477 Share on other sites More sharing options...
bobbinsbro Posted November 8, 2008 Share Posted November 8, 2008 then just add an iterator to your loop: <?php $i = 1; //initialize iterator do { ?> <tr> <td height="22"><span class="style9"><?php echo $row_Recordset2['Module name']; ?></span></td> <td><div align="center"><?php echo $row_Recordset2['Module ID']; ?></div></td> <td><div align="center"><?php echo $row_Recordset2['credits']; ?></div></td> <td><div align="center"><?php echo $row_Recordset2['Completed']; ?></div></td> <td><input name="module<?php echo $i; //add iterator value to the checkbox name ?>" type="checkbox" id="module" value="<?php echo $row_Recordset2['Module name']; ?>" /></td> </tr> <?php ++$i; //increment iterator } while ($row_Recordset2 = mysql_fetch_assoc($Recordset2)); ?> Quote Link to comment https://forums.phpfreaks.com/topic/131928-displaying-data-on-to-another-page-by-check-box/#findComment-685479 Share on other sites More sharing options...
Yesideez Posted November 8, 2008 Share Posted November 8, 2008 I think this is where you'd do it: <input name="module<?=$row_Recordset2['Module ID']?>" type="checkbox" id="module" value="<?=$row_Recordset2['Module name']?>" /> Try that and view the source of the page and see if the name of each checkbox is unique depending on the ID of each row. Quote Link to comment https://forums.phpfreaks.com/topic/131928-displaying-data-on-to-another-page-by-check-box/#findComment-685480 Share on other sites More sharing options...
ma5ect Posted November 8, 2008 Author Share Posted November 8, 2008 created with repeat region <form name="orderform" action="confirm-order.php" method="post"> <table width="757" border="3" align="center"> <tr> <td width="133"><div align="center" class="style12"> <div align="center">Module Name</div> </div></td> <td width="106"><div align="center" class="style12"> <div align="center">Module ID</div> </div></td> <td width="104"><div align="center" class="style12"> <div align="center">Credits</div> </div></td> <td width="117"><div align="center" class="style12"> <div align="center">Completed</div> </div></td> <td width="110"><div align="center" class="style12"> <div align="center">Attempts</div> </div></td> <td width="100"><div align="center" class="style12"> <div align="center">Level</div> </div></td> <td width="37"><div align="center">Select</div></td> </tr> <?php do { ?> <tr> <td height="22"><span class="style13"><?php echo $row_Recordset2['Module name']; ?></span></td> <td><div align="center" class="style14"><?php echo $row_Recordset2['Module ID']; ?></div></td> <td><div align="center" class="style14"><?php echo $row_Recordset2['credits']; ?></div></td> <td><div align="center" class="style14"><?php echo $row_Recordset2['Completed']; ?></div></td> <td><div align="center" class="style14"><?php echo $row_Recordset2['Attempts']; ?></div></td> <td><div align="center" class="style14"><?php echo $row_Recordset2['Level']; ?></div></td> <td><div align="center"> <input name="module" type="checkbox" id="module" value="<?php echo $row_Recordset2['Module name']; ?>" /> </div></td> </tr> <?php } while ($row_Recordset2 = mysql_fetch_assoc($Recordset2)); ?> </table> <p align="center"> <input type=submit value="Submit" /> </form> Quote Link to comment https://forums.phpfreaks.com/topic/131928-displaying-data-on-to-another-page-by-check-box/#findComment-685482 Share on other sites More sharing options...
Yesideez Posted November 8, 2008 Share Posted November 8, 2008 I prefer to use while() loops as a do() loop will always be executed at least once because the clause is encountered after the code has been run. I'm not sure what type of MySQL call you're running but is there a chance your call can return nothing? If there is, you'll be better off using while() instead. Quote Link to comment https://forums.phpfreaks.com/topic/131928-displaying-data-on-to-another-page-by-check-box/#findComment-685487 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.