Jump to content

Recommended Posts

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]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.