molly31 Posted March 18, 2006 Share Posted March 18, 2006 I have a database already set up and want to display records from it on another page, selected by 'ticking' a checkboxHow do i do it?Thanks in advance for any help Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted March 18, 2006 Share Posted March 18, 2006 This will print off all records in the database, along with column names in a single table. It will also place a checkbox at the beginning of each row. You will have to wrap it in your form tags. When it is submittted, you will have in $_POST all of the checkboxes and the ones that are selected will have a value of "on".Do a print_r on $_POST to see what the result is.You will also have to supply the db connection and the tablename as $tablename.[code]<?php$query = "SHOW COLUMNS FROM tablename";$result = mysql_query($query);$html = ' <table> <tr>'; while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { if ($row['Key'] == "PRI") { $primarykey = $row['Field']; } $html .= "<th>" . $row['Field'] . "</th>";}$html .= " </tr>";$query = "SELECT * FROM tablename";$result = mysql_query($query);while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $html .= "<tr><td><input type=\"checkbox\" name=\"" . $row[$primarykey] . "\"></td>"; foreach ($row as $value) { $html .= "<td>$value</td>"; } $html .= "</tr>";}$html .= " </table>";[/code] Quote Link to comment 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.