It works, but just for the first row selected from the table. I think that
the problem is that the checkboxes are declared inside a while loop. If i
declare manually all checkboxes it works. Any ideas ? Or maybe I'm doing
something wrong?
############################################################################
####
echo "<form method=\"post\" action=\"selectare.php?ids[]\">";
echo "<input type=\"Submit\" value=\"Trimite\">";
/* Connecting, selecting database */
$link = mysql_connect("localhost", "root", "adrian")
or die("Could not connect");
print "Connected successfully";
mysql_select_db("menagerie") or die("Could not select database");
/* Performing SQL query */
$query = "SELECT * FROM reclamatie";
$result = mysql_query($query) or die("Query failed");
/* Printing results in HTML */
echo "<table border=1>";
echo
"<tr><td></td><td>ID</td><td>Subject</td><td>Open</td><td>Close</td></tr>";
while($row = MySQL_fetch_array($result)) {
echo "<tr><td><form><input type=\"checkbox\" method=\"post\"
name=\"ids[]\" value=\"{$row['id']}\"></form></td>";
echo "<td><a href=\"lowerframe.php?id={$row['id']}\"
target=\"lowerframe\">{$row['id']}</a></td>";
echo "<td>{$row['subject']}</td>";
echo "<td>{$row['open']}</td>";
echo "<td>{$row['close']}</td></tr>";
}
echo "</table>";
/* Free resultset */
mysql_free_result($result);
/* Closing connection */
mysql_close($link);
echo "</form>";
?>
###############################
//selectare.php (just displays the id's of selected checkboxes)
//$useri=$_POST['useri'];
$ids=$_POST['ids'];
reset($ids);
while (list ($key, $value) = each ($ids)) {
echo "$value<br />\n";
}
?>
#####################################################
As I said, when I select the first checkbox, I get the id, but when I select
any other checkbox, I get the errors
PHP Notice: Undefined index: ids in selectare.php
PHP Warning: Variable passed to each() is not an array or object in
selectare.php
----- Original Message -----
From: "John W. Holmes" <[EMAIL PROTECTED]>
To: "'Adrian Partenie'" <[EMAIL PROTECTED]>; "'php'"
<[EMAIL PROTECTED]>
Sent: Thursday, November 28, 2002 5:54 PM
Subject: RE: [PHP] mysql, php, checkbox
> > I'm displaying the content of a mysql table with autoincrement index.
> I
> > want to be able to select the each row from the table using the check
> > boxes. In order to do that, i want to assign to each checkbox the
> > name=index of selected row.
> > I assign to the checkboxes the value of selected id, but I can't
> > retreiveit later for further processing. My code looks like this
> >
> > $query = "SELECT * FROM reclamatie";
> > $result = mysql_query($query) or die("Query failed");
> >
> > /* Printing results in HTML */
> >
> > echo "<table border=1>";
> > echo
> >
> "<tr><td></td><td>ID</td><td>Subject</td><td>Open</td><td>Close</td></tr
> >"
> > ;
> >
> > while($row = MySQL_fetch_array($result)) {
> > echo "<tr><td><form><input type=\"checkbox\" method=\"post\"
> > name=\"{$row['id']}\"></form></td>"; // ??????????
>
> It looks like your naming it as a number, which won't work for PHP. You
> want to name all of your checkboxes the same, with a [] on the name to
> make the results an array in PHP.
>
> ... name="id[]" value="{$row['id']}"
>
> Then, you'll have $_POST['id'][x] as an array in PHP. Only the
> checkboxes that were selected will be in the array, from zero to however
> many were checked. The value of $_POST['id'][x] will be whatever was in
> the value="..." part of the HTML checkbox...
>
> ---John Holmes...
>
>
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php