2
    <?php

    include ("database.php");               
    $qry = "Select * from tbnam where $option like '%$content%'";
    $result=mysql_query($qry);        
    while ($row =mysql_fetch_array($result))
    {
    $id=$row['id'];
    ?>
//creating table
    <tr><?echo "<td><input type=\"checkbox\" name=\"checkbox[]\" id=\"checkbox[]\"  value=\"".$row['id']."\" /></td>";?>
    <td><? echo $row['name'];?></td>
    <td><? echo $row['address'];?></td>
    <td><? echo $row['email'];?></td>
    <td><? echo $row['telephone'];?></td>
    <td><? echo $row['problem'];?></td>
    <td><? echo $row['reply_query'];?></td>
    <td><? echo $row['type'];?></td>
    <td><? echo $row['other'];?></td></tr>
    <?php
    }
    ?>
    <input type="submit" name="search" value="Print" size="10"/>
    </form>
    </table>

how i got the checkbox values? any need of passing $id in checkbox[] array ? if yes how it is possible? help me...name=\"checkbox["\".$id"\"]\"

2
  • 1
    Welcome on Stack Overflow ! Try var_dump($_POST['checkbox']);. Commented Oct 21, 2011 at 13:17
  • First line: include does not need the (). Commented Oct 21, 2011 at 13:20

3 Answers 3

2

By writing

<tr><?echo "<td><input type=\"checkbox\" name=\"checkbox[]\" id=\"checkbox[]\"  value=\"".$row['id']."\" /></td>";?>

you have designed a form which returns an array of values with each value corresponding to a checkbox that has been "checked".

In this example the POST variable that points to this array will be $_POST['checkbox']. Since you have set the value of each checkbox as $row['id'], each element in the checkbox array will have the 'id' value corresponding to each checkbox that you have checked.

You can check out these values like this:

foreach($_POST['checkbox'] as $value)
{ 
  echo $value;
}

or simply by saying:

echo var_dump($_POST['checkbox']);

Hope this makes it clear. :)

Sign up to request clarification or add additional context in comments.

Comments

1

$_POST['checkbox'] will give you an array of the value you checked.

Comments

0

What is the need of the array here (checkbox[]) , when you are showing a single checkbox element here. Also for IDs, we need not to mention as arrays.

You simply use like below

<tr><?echo "<td><input type=\"checkbox\" name=\"checkbox\" id=\"checkbox\"  value=\"".$row['id']."\" /></td>";?>

And While reading,

if (isset($_POST["checkbox"])) // Returns true if checked
{

}

Hope it helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.