Jump to content

php checkbox,,array help...


popmotsy

Recommended Posts

HIii To all,,

 

In my project ,,,

 

I want to extract data using checkbox,,,that means,,

 

there is some checkbox whose value same as the table feilds.

Now user can select the checkbox, and on submit only selected

data comes out. I make array of checkboxes.

 

I have write a code for this,,,plz chechk it

 

 

<?php require_once("include/left.php"); ?>

<table border="0" width="990">

 

<tr>

<TD>

<table align="center" border="1" style="font-size:12">

        <form name="frm354" method="post" >

       

Select Fields To Make A Report</br></br>

<input type="checkbox" name="answer[]" value="sbi_id"/>Id </br>

<input type="checkbox" name="answer[]" value="billcycle"/> Billcycle </br>

<input type="checkbox" name="answer[]" value="prioritydelievary"/> Priority Delievary </br>

<input type="checkbox" name="answer[]" value="sbi_barcodeno"/> Barcode1 </br>

<input type="checkbox" name="answer[]" value="podno"/> POD No </br>

<input type="checkbox" name="answer[]" value="recievedby"/> Recieved By</br>

<input type="checkbox" name="answer[]" value="relation"/>Relation</br>

<input type="checkbox" name="answer[]" value="remark"/> Remark</br>

<input type="checkbox" name="answer[]" value="bcode"/> Barcode2</br>

<input type="checkbox" name="answer[]" value="ldate"/>Letter date</br>

<input type="checkbox" name="answer[]" value="acno"/> Account No</br>

<input type="checkbox" name="answer[]" value="customername"/> Customername</br>

<input type="checkbox" name="answer[]" value="compname"/> CompanyName</br>

<input type="checkbox" name="answer[]" value="address"/> Address</br>

<input type="checkbox" name="answer[]" value="rphone"/> Resi Phone</br>

<input type="checkbox" name="answer[]" value="ophone"/> Office Phone</br>

<input type="checkbox" name="answer[]" value="cityid"/> City</br>

<input type="checkbox" name="answer[]" value="pcode"/> PinCode</br>

 

 

 

<input type="submit" name="submit" value="submit"/>

 

</form>

 

 

 

</table>

</form>

 

<?php

 

 

if(isset($_POST['submit']))

{

for($i=0;$i<count($_POST['answer']);$i++)

{

$ans=$_POST['answer'];

// // echo $ans1;

$sql="select * from xsbi_feedback ";

// print($sql);

$result=mysql_query($sql);

while($data=mysql_fetch_array($result))

{

 

//HOW CAN i GET VALUES..

}

 

}

 

}

?>

 

plz help,,,thanks..

 

Link to comment
https://forums.phpfreaks.com/topic/165032-php-checkboxarray-help/
Share on other sites

if they are static, you should know how many are they.

 

use this code:

 

<input type="checkbox" name="answer_1" value="sbi_id"/>Id </br>
<input type="checkbox" name="answer_2" value="billcycle"/> Billcycle </br>
<input type="checkbox" name="answer_3" value="prioritydelievary"/> Priority Delievary </br>
<input type="checkbox" name="answer_4" value="sbi_barcodeno"/> Barcode1 </br>
...

 

Then you php script:

 

<?php
$temp = '';
for($i=1;$i==<COUNT HERE>;$i++)
{
	if($_POST['answer_' . $i])
	{
		$temp .= $_POST['answer_' . $i];
		$temp .= '^^^^'
	}
}
?>

 

Then, you have all posted values in a string named '$temp'

Save that in you DB. to read them, you can easily use `explode` function.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.