OrganizedChaos
MIS
I have some code that reads from a db and displays all contents of one of its fields..
As you can see it reads from the managers table and is sorting it by the name field.
here is the code..
<?
mysql_connect('localhost',$username,$password);
mysql_select_db($database) or die("Unable to select database");
$query=("SELECT * FROM managers ORDER BY name ASC");
$result=mysql_query($query);
if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
}
$num=mysql_numrows($result);
mysql_close();
echo "<table border=0 width=800 cellpadding=2 cellspacing=2 align=center>";
echo "<tr>";
$i=0;
while ($i < $num) {
$name=mysql_result($result,$i,"name");
echo "<td align=right><input type=checkbox value=$name name=$name />$name </td>";
$i++;
}
?>
So I am creating a table that reads each item in the field and displays it as a checkbox, giving each checkbox a name and value of the name it pulls from the DB
lets say the names in the db are Alan, Brett, and Cathy
How would I assign these names as variables so they are sent to my next from??
for exapmle if just Alan is checked, on my next form I dont want to put $_POST['Alan'], I would like it to be a little more flexible then that if possible... Plus I want to require the users to check 2 of the boxes to continue.
I was thinking I could read from the same db and do something like this on the next form:
if $_POST[$name] {
do whatever
}
but that is not the right answer..
I want this to work with whatever name is inserted into the db..
?? Im fairy green at php still and I have no idea how to even look this one up.. Any ideas?
Thanks,
Mike