dymanic populating checkboxes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • calms

    dymanic populating checkboxes

    HI,

    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
    require_once('. ./dbinfoinc.php') ;


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


    $num=mysql_numr ows($result);
    mysql_close();


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



    $event_id=mysql _result($result ,$i,"event_id") ;


    $event_name=mys ql_result($resu lt,$i,"event_na me");


    $event_publish= mysql_result($r esult,$i,"publi sh");
    // if(($event_publ ish) == 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'
    class=$c>$event _name</td>
    <td class='navText'
    align='center' class=$c><input type='checkbox'
    name='publish' if($event_publi sh==1){'CHECKED ';}?></td>
    <td class='navText'
    align='center' class=$c><a
    href='delete_ev ent.php?event_i d=$event_id'>$t ake_action</a></td></tr>";

    $i++;
    }
    ?>


    thanks

  • Kimmo Laine

    #2
    Re: dymanic populating checkboxes

    "calms" <calmsqurill@gm ail.comwrote in message
    news:1156836800 .803848.266940@ m79g2000cwm.goo glegroups.com.. .
    HI,
    >
    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,
    echo "<tr>
    <td Class='navText'
    align='center' class=$c>$event _id</td>
    <td class='navText'
    class=$c>$event _name</td>
    <td class='navText'
    align='center' class=$c><input type='checkbox'
    name='publish' ?></td>
    <td class='navText'
    align='center' class=$c><a
    href='delete_ev ent.php?event_i d=$event_id'>$t ake_action</a></td></tr>";
    >
    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:

    if($event_publi sh==1){
    $checked_state = 'checked="check ed"';
    } 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 päivittyvä nettisarjis
    spam@outolempi. net || Gedoon-S @ IRCnet || rot13(xvzzb@bhg byrzcv.arg)


    Comment

    • calms

      #3
      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.

      calms

      Kimmo Laine wrote:
      "calms" <calmsqurill@gm ail.comwrote in message
      news:1156836800 .803848.266940@ m79g2000cwm.goo glegroups.com.. .
      HI,

      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,
      >
      >
      echo "<tr>
      <td Class='navText'
      align='center' class=$c>$event _id</td>
      <td class='navText'
      class=$c>$event _name</td>
      <td class='navText'
      align='center' class=$c><input type='checkbox'
      name='publish' ?></td>
      <td class='navText'
      align='center' class=$c><a
      href='delete_ev ent.php?event_i d=$event_id'>$t ake_action</a></td></tr>";
      >
      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:
      >
      if($event_publi sh==1){
      $checked_state = 'checked="check ed"';
      } 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 päivittyvä nettisarjis
      spam@outolempi. net || Gedoon-S @ IRCnet || rot13(xvzzb@bhg byrzcv.arg)

      Comment

      Working...