help with checkboxes (multidimensional array) in HTML forms

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lkj
Forum Newbie
Posts: 6
Joined: Mon Feb 23, 2004 12:09 pm
Location: toronto

help with checkboxes (multidimensional array) in HTML forms

Post by lkj »

Hi All,

Happy Monday!

I want to show the fields of each table in my DB as checkboxes in a user form that user can check and my program selects the column data from the DB depeneding on checked boxes.

e.g.

Table 1

fields as checkboxes

Table 2

fields as checkboxes

How do I get the info about the checked fields in each of the tables?


I hope it's clear enough.

Thank you all.

lkj
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

hi - I assume u know how to connect to the database and pull info from it, so all u need is a loop to display the info in the DB and a form as checkboxes to accomodate the info... simple:

Code: Select all

<?php
$sql = "select * from table_name order by id";
//I assume u have a ID field in your DB so each field has its own idenification key
$result = mysql_query($sql);
$id = $row["id"];
while ($row = mysql_fetch_array($result)) {
echo "<form action=delete.php$delete POST><input type=checkbox name=delete[] value=$id> delete whatever";

//now on delete.php
if(isset($delete)) {
run whatever u want here
}
?>
Now this will display the table and when checked, will send to delete.php (like on mine I have it so I can delete msgs of the checkboxed items displayed in my table.. u can modify the code to whateevr u like

and so u know, delete[] will make the data that is checked into a array so u can pass multiple variiables..

What did u want done with the data in the db anyway? edit them, delete them?
Post Reply