-1

I am beginner in PHP I'm trying to generate PDF but I have trouble in how can I display data from selected checkbox. For example I want to select two rows or three or four using this select * from table where id in ($stk) but its displays blank.

 <input type='checkbox' name='stick[]' id="stick" value =' <?php echo $row['id']; ?>'        /> 


    $name = isset($_POST['stick'])?$_POST['stick']:NULL; 
    if(isset($_POST['stick'])){ 
             foreach ($name as $stk){

             $query = "SELECT * FROM machine_and_equipments where MENo in($stk)";  
    $result = mysql_query($query) or die (mysql_error());

    while($query_row = mysql_fetch_assoc($result)){
    $controlnumber = $query_row['MENo'];
    $assetname = $query_row['machine_equipments_name']; 
    $location = $query_row['Location'];    

$text = sprintf("%s\n%s\n%s\n%s\n%s", "Koushin Mechatronics Manufacturing Philippines Inc. ", '                                   PROPERTY STICKER', 'Control No.     :    '. $controlnumber .' ', 'Asset Name    :    '. $assetname .' ',  'Location          :   '. $location .' ');}
KENN
  • 1
  • 1
  • 6
  • `**SELECT` why do you put `**` here? – u_mulder Sep 04 '14 at 06:11
  • omit the `**`? in your query – Ker p pag Sep 04 '14 at 06:20
  • never mind the ** i allready removed look this example this "SELECT * FROM machine_and_equipments where MENo in(1,2,3)" it is correct but when i put variable "SELECT * FROM machine_and_equipments where MENo in($stk)" its freaking me how can i suppose to put value with comma 1,2,3 in $stk – KENN Sep 04 '14 at 06:34

1 Answers1

0

You got a pretty good base to begin with, but there is a small error, you are looping through your sql calls. Where you should be making a comma sepperated list for your IN ($stk).

Take a look at this answer: How to convert items in array to a comma separated string in PHP?

so

foreach ($name as $stk){

should be

$stk = implode(',', $name);

and remember to remove the last "}" since you don't need that anymore

Community
  • 1
  • 1
Magic-Mouse
  • 603
  • 10
  • 21
  • implode is correct i can display 1 data but when i choose multiple it display blank.. – KENN Sep 05 '14 at 03:53