jeudi 14 avril 2016

Checkboxes - output, see if they are checked or not in php

Stuck again, checkboxes are really making my head spin :P

So input works flawless, but now for the output.

database selection: Getting the event id's where the user id = user id (works)

 $statement2 = $this->Db->prepare("SELECT RO_events.e_name, RO_eventsvol.id, RO_eventsvol.e_id FROM RO_events INNER JOIN RO_eventsvol ON RO_events.e_id=RO_eventsvol.e_id WHERE RO_eventsvol.id ='$p_id'");
        $statement2->execute();
        $dataRows2 = $statement2->fetchall();

Getting all events and event-id's for the table build and the checking:

 $statement4 = $this->Db->prepare("SELECT * FROM RO_events");
        $statement4->execute();
        $dataRows4 = $statement4->fetchall();

Building the table:

 foreach ($dataRows4 as $rows4) {   
    }
       ?>

   <table class="center"><th colspan="2">Festivals</th><tr>

    </tr><tr>
       <?php

       $i = 0;

       foreach($dataRows4 as $rows4){
           $i++;

echo '<td><input type="checkbox" name="fest[]" value="'.$rows4[0].'">'.$rows4['e_name'].' </td>'; }

if($i == 2) { 
    echo '</tr><tr>';

      } 
       ?>       
</table>

And now to see if the checkboxes are checked... I've tried a lot of things but the checkboxes only check the highest id and ignores the rest.. Who can help me find the right solution to this?

I know it should be something like: 1) putting the dataRows2['t_id'] in an Array 2) if statement to check:

 if ($rows4[0] == $dataRowsarray ) {echo '<td><input type="checkbox" name="fest[]" value="'.$rows4[0].'">'.$rows4['e_name'].' checked="checked"</td>'; } 
else 
{ echo '<td><input type="checkbox" name="fest[]" value="'.$rows4[0].'">'.$rows4['e_name'].' </td>'; }




Aucun commentaire:

Enregistrer un commentaire