dymanic populating checkboxes

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

First of all im vry new to PHP, i like to retrieve a value from DB,
accordingly i like to display the checkbox, either checked or not.

Now im able to retrieve the value from DB, i can show even show the
checkbox, but i cant make it checked????

Can anyone help, plzzzzzzz!!!

the Code i used to display as follows,

                                #Require the database class

                                #Get an array containing the resulting
                                $query = "SELECT * FROM event";
                                $result = mysql_query($query);


                                while ($i < $num) {
                                    if(($i % 2) == 0) { $c =
'"TableDetail"'; }
                                        else { $c = '"TableDetail2"'; }



                               // if(($event_publish) == 0) {
$event_publish = 'No'; }
                               //       else { $event_publish = 'YES';
                                          $take_action = 'Delete';
                                        echo "<tr>
                                        <td Class='navText'
align='center' class=$c>$event_id</td>
                                        <td class='navText'
                                        <td class='navText'
align='center' class=$c><input type='checkbox'
name='publish' if($event_publish==1)?></td>
                                        <td class='navText'
align='center' class=$c><a



Re: dymanic populating checkboxes

Quoted text here. Click to load it

IF-statements don't work like that, inside a string. You've chosen a very  
peculiar way of studying php if you've managed to get all the way to  
retrieving information from a databases but have no idea how if's and  
strings work or don't work.

Okay, so you have this really big string and inside it you have an if  
statement. That won't do. You have to perform the if-test outside the  
string. Try this. Before echoing the string, write the following code:

    $checked_state = 'checked="checked"';
} else {
    $checked_state = '';

And then, inside the string:
echo "...<input type='checkbox'name='publish' $checked_state >...";

And see how it works.

And then the lecture from a seasoned and old php veteran....

I started "coding" by looking into source codes of other websites, studied  
the html structures, javascript etc. several years ago. It was in the 90's,  
when this thing called "the internet" got big. It was a fun way of learning  
and kept me interested, but also very frustrating. Since then I've taken  
courses and studied programming really hard and finally stopped copy-pasting  
other peoples codes and write everything myself, now that I know how. I  
admire your enthusiasm and I strongly encourage you to study php, but start  
from the basic stuff. It's very simple and boring first, I mean how exciting  
can 1+2 be? I know, boring as hell, but you gotta learn the ground rules of  
the language before you can really get into this programming stuff. Keep up  
the good work!

"Ohjelmoija  on  organismi  joka  muuttaa  kofeiinia  koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti pivittyv nettisarjis
spam@outolempi.net || Gedoon-S @ IRCnet || rot13(xvzzb@bhgbyrzcv.arg)  

Re: dymanic populating checkboxes

thks a lot.Yes it worked. Also thks for pointing my mistakes tht i
didnt learn in order. Yes i didnt follow any course or book....i learn
through Internet.


Kimmo Laine wrote:

Quoted text here. Click to load it
Quoted text here. Click to load it

Site Timeline