Help using arrays needed.
Posted: Mon May 22, 2006 7:39 am
Hi
Ive managed to populate a table using an array called from a MYSQL database. The problem im having is as follows..
What im after is when the user selects the required radio button, the form submits this value along with the ID called from the MYSQL database.
Im getting the radio button value but the ID is always the last in the array. Any help would be appreciated....Code follows...
Ive managed to populate a table using an array called from a MYSQL database. The problem im having is as follows..
What im after is when the user selects the required radio button, the form submits this value along with the ID called from the MYSQL database.
Im getting the radio button value but the ID is always the last in the array. Any help would be appreciated....Code follows...
Code: Select all
<?php
$connection = mysql_connect("localhost","****","");
mysql_select_db("dbase", $connection);
$result = mysql_query ("SELECT * FROM access", $connection);
$nrows = mysql_num_rows($result);
if($nrows != 0)
{
print "<form action='sub.php'><TABLE border=1>";
for ($j=0;$j<$nrows;$j++ )
{
$row = mysql_fetch_array($result);
if ($row["access"] == "1") {
$colour = "red";
} else {
$colour = "black";
}
$hid[] = $row["id"];
# print "<TD>" . $row["id"] . "</TD>";
print "<TD><font color = '$colour'>" . $row["username"] . "</font></TD><TD><input type='radio' name='block' value='0'><input type='radio' name='block' value='1'><input type='hidden' name='usr' value='$row[username]'><input type='submit' value='GO'></TD></TR>";
}
print "</table></form>\n";
}
?>Code: Select all
sub.phpCode: Select all
<?php
$data = $_GET['block'];
$hid = $_GET['usr'];
echo "$data";
echo "$hid";
?>