user711897
user711897

Reputation: 11

Display checked checkbox record from database

I have looked through similar problems and solution but somehow only half way help me with my problem. I'm trying to make a form to checked more than one record from MySQL database and display the checked record to another page. Somehow I managed to do the page with check boxes but I don't know how to display the record checked. It can only display the first row of the record or all the records regardless which box are checked.

This is checkbox page

$columns = count($fieldarray); 
//run the query 
$result = mysql_query(
  "SELECT * FROM request_item 
   ORDER BY request_item.IllNo DESC LIMIT 0, 6") or die(mysql_error()); 
$row = mysql_num_rows($result);

while($row=mysql_fetch_array($result)) 
{
  {
    $rows[] = $row['IllNo'];
  }

  foreach($rows as $value); 
  echo "";
  echo " ";
  echo $row['IllNo'];
  echo ""; 
}
echo "";
?>

This is display record checked

$columns = count($fieldarray); 
//run the query 
$result = mysql_query(
  "SELECT * FROM request_item 
   ORDER BY request_item.IllNo DESC LIMIT 0, 6") or die(mysql_error()); 
$row = mysql_num_rows($result);

while($row=mysql_fetch_array($result)) 
{ 
  $rows[]=$row['IllNo'];  
  foreach($rows as $value); 
  if ($rows= 'checked') { 
    echo "";
    echo $value; 
  }

Any help are welcome. Thank you.

Upvotes: 1

Views: 5692

Answers (1)

Coder1
Coder1

Reputation: 13321

There's actually a lot of problems with that script including syntax errors, calling the wrong variable name, form not opening where it should, invoking PHP after you already have, etc...

To get a good answer to you, you should share what make $row['IllNo'] should equal to indicate if it should be checked or not.

I reformatted it a bit and this may give you a good start.

<form NAME ="form1" METHOD ="POST" ACTION ="dari.php">
<table>
<?php
$columns = count($fieldarray);
//run the query
$result = mysql_query("SELECT * FROM request_item ORDER BY request_item.IllNo DESC LIMIT 0, 6") or die(mysql_error()) ;
$row = mysql_num_rows($result);


while($row=mysql_fetch_array($result)) {
  echo "<tr><td>";
  echo "<Input type = 'Checkbox' Name ='ch1' value ='ch1'";
  // check checked if it is. this will be checked if $row['IllNo'] has a value
  // if there were a condition to make it checked, you would put the condition
  // before the ?
  echo $row['IllNo'] ? ' checked' : '';
  echo ' />';
  echo $row['IllNo'];

  echo "</td></tr>";
}
?>
</table>
<INPUT TYPE = "Submit" Name = "Submit1" VALUE = "Choose your books">
</FORM>

Upvotes: 1

Related Questions