manton Posted April 27, 2007 Share Posted April 27, 2007 Hello, I have a table on a form which contains records that can be multiple selected by checkboxes. A submit button sucessfully sends the record IDs of the checked records to the next page. I want to display the records that were selected via the checkboxes, but the problem is that I get only the first of them. Any help would be really appreciated, thanks Link to comment https://forums.phpfreaks.com/topic/48979-use-checkboxes-to-display-selected-records/ Share on other sites More sharing options...
Psycho Posted April 27, 2007 Share Posted April 27, 2007 No way to help without seeing some of your code. In particular, the form with the checkboxes would be helpful as well as the code you have to display the posted values. Link to comment https://forums.phpfreaks.com/topic/48979-use-checkboxes-to-display-selected-records/#findComment-239973 Share on other sites More sharing options...
manton Posted April 27, 2007 Author Share Posted April 27, 2007 Ok, and let me be more specific... I have a database (with names for example) and i use a table to display them. Users want to print the names but not all of them so i use checkbox to select some of the records that must be displayed on the printable page. The problem is that i don t know how can i get only the records that are selected. How can i do that? myform <form id="form1" name="form1" method="get" action="tickets.php"> <input type="submit" name="Submit" value="Submit" /> <table border="1"> <tr> <td> </td> <td>ExamCenter</td> <td>Area</td> <td>InterviewExamCenter</td> <td>SchoolCode</td> <td>Name</td> <td>Surname</td> <td>Fathername</td> <td>BinSerialCode</td> <td>LevelDescription</td> <td>Comments</td> <td>WrittingDate</td> <td>WrittingTimeStart</td> <td>WrittingTimeEnd</td> <td>InterviewDate</td> <td>InterviewTime</td> <td>InterviewRoom</td> </tr> <?php do { ?> <tr> <td> <input name="" type="checkbox" value="<?php echo $row_Recordset1['BinSerialCode']; ?>" /> </td> <td><?php echo $row_Recordset1['ExamCenter']; ?></td> <td><?php echo $row_Recordset1['Area']; ?></td> <td><?php echo $row_Recordset1['InterviewExamCenter']; ?></td> </tr> <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?> </table> </form> the opening page <?php require_once('../Connections/palso.php'); ?> <?php $var = $_GET['checkbox']; session_start(); $_SESSION['ses_check'] = $var; echo $_SESSION['ses_chek']; $maxRows_data = 2; $pageNum_data = 0; if (isset($_GET['pageNum_data'])) { $pageNum_data = $_GET['pageNum_data']; } $startRow_data = $pageNum_data * $maxRows_data; $colname_data = "-1"; if (isset($_SESSION['BinSerialCode'])) { $colname_data = (get_magic_quotes_gpc()) ? $_SESSION['BinSerialCode'] : addslashes($_SESSION['BinSerialCode']); } mysql_select_db($database_palso, $palso); $query_data = sprintf("SELECT * FROM `data` WHERE BinSerialCode = '%s' ORDER BY BinSerialCode ASC", $colname_data); $query_limit_data = sprintf("%s LIMIT %d, %d", $query_data, $startRow_data, $maxRows_data); $data = mysql_query($query_limit_data, $palso) or die(mysql_error()); $row_data = mysql_fetch_assoc($data); if (isset($_GET['totalRows_data'])) { $totalRows_data = $_GET['totalRows_data']; } else { $all_data = mysql_query($query_data); $totalRows_data = mysql_num_rows($all_data); } $totalPages_data = ceil($totalRows_data/$maxRows_data)-1; ?> <?php echo $_SESSION['ses_kod']; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-7" /> <title>Untitled Document</title> <link href="styles.css" type="text/css" rel="stylesheet" /> </head> <body> <div id="container"> <?php do { ?> <table width="800"> <tr> <td colspan="4"><h3><?php echo $row_data['Surname']; ?> <?php echo $row_data['Name']; ?></h3></td> <td><h3><?php echo $row_data['BinSerialCode']; ?></h3></td> </tr> </table> <br /> <?php } while ($row_data = mysql_fetch_assoc($data)); ?></div> </body> </html> <?php mysql_free_result($data); ?> Link to comment https://forums.phpfreaks.com/topic/48979-use-checkboxes-to-display-selected-records/#findComment-240027 Share on other sites More sharing options...
Psycho Posted April 27, 2007 Share Posted April 27, 2007 Here's your problem: <input name="" type="checkbox" value="<?php echo $row_Recordset1['BinSerialCode']; ?>" /> You did not give the checkboxes a name - specifically an array name. In your processing code you are referencing the values using $_GET['checkbox'] (I guess when there is no name it is using the field type as the name). So, how would the page access each specific checkbox? It can't. You need to give the checkboxes either individual names (would be more difficult, but not impossible) or give them the same array name: <input name="record_id[]" type="checkbox" value="<?php echo $row_Recordset1['BinSerialCode']; ?>" /> Only checked fields pass their values. So, in your processing code you can access the values of all the checked values like this: foreach ($_GET['record_id'] as $delete_id) { // delete the record with id $delete_id } I would personally use POST in this situation as sending record ids on the query string (especially for delete purposes) can be problematic. In any case, you should always validate the values before running any queries. Link to comment https://forums.phpfreaks.com/topic/48979-use-checkboxes-to-display-selected-records/#findComment-240044 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.