Link to home
Start Free TrialLog in
Avatar of derrida
derrida

asked on

problem presenting dynamic php data in a non-text elements

hi
i have a database table called "people" and the fields are:"name","isactor","isdirector","age".
i have no problem to echo the name and the age in a text field.
but i want that is the person is an actor or a director it will show in a checkbox or a radio button. so one will be selected while the other will not be selected.

so i wrote this code:
 <tr>
      <td>is he an actor:</td>
      <td><label>
        <input name="radio3" type="checkbox" value="<?php echo $row_peopleQ['people_isactor']; ?>"  />
      </label>        </td>
    </tr>
      <tr>
      <td>is he a director: </td>
      <td><label>
        <input name="radio4" type="checkbox" value="<?php echo $row_peopleQ['people_isdirector']; ?>"  />
      </label></td>
      </tr>
    <tr>

but while the name and the age are presented the checkboxes are not selected, even though that when i replaced them with textfields the correct values are presented.

can anyone help me? how do i present dynamic data in non-text elements?

best regards

ron
Avatar of Rouchie
Rouchie
Flag of United Kingdom of Great Britain and Northern Ireland image

You have to check the value from the database and echo the word CHECKED into the checkbox item in the HTML page if the database value is TRUE , i.e.

 <input type="checkbox" name="radio3" checked />

I'm not a php programmer, but I think this site might have the answer:
http://www.globalissa.com/articles/articleCheckbox.php

Googling for "php checkbox" will certainly provide the logic you need, unless Jason provides the answer first... :-)
Avatar of derrida
derrida

ASKER

hi
thanks for the answer.
this page only present the info from the database and does not send it anywhere. in the first page the user select a name and he is going to this page where he need to see all the other details about thin name that was selected.

in any case i tried to change things according the link you gave (which is very good) but it still does not work.

any suggestions?


best regards

ron
Okay well here's my first ever attempt at php.  Jason will be appalled.
This presumes by the way, that the database stores the people_isactor value as a true/false bit value.

<td>
      <label>is he an actor:</label>
</td>
<td>
      <input name="radio3" type="checkbox" value="
            <?php
            if ($row_peopleQ['people_isactor']===true)
                  {
                  echo "checked";
                  }
            ?>
      " />
</td>
Avatar of derrida

ASKER

hi
the people_isactor in the database is a tinyint (1) with a default of 0.
i tried what you have suggested and it still does not come checked when it should be.

for example: i have jim carrey and in the database in the poeple_isactor  he is =1, that means he is an actor.
all i want is that they page loads and the checkbox is ckecked for "actor".
again i have no problem if its a textfield only when it is a checkbox or a radio button.

ron
Okay try the modified version that checks for an integer value

<td>
      <label>is he an actor:</label>
</td>
<td>
      <input name="radio3" type="checkbox" value="
            <?php
            if ($row_peopleQ['people_isactor']==1)
                  {
                  echo "checked";
                  }
            ?>
      " />
</td>
Avatar of derrida

ASKER

hi
obviously i already tried the "true" and "1", i did that immediatly and even before i posted here.
in any case i tried again and it still does not work.
i`m sure its something very simple that i just miss.


ron
Have you correctly used either the double or triple equals sign (== or ===) that compares values and types?
Avatar of derrida

ASKER

hi
yeah and just for a try i tried them both, and no result.
the bizzare thing is that this is not a form  that one need to take care of passing variables, this is just a presentational issue ,and to get stuck with it is frastrating.

ron
ASKER CERTIFIED SOLUTION
Avatar of Rouchie
Rouchie
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of derrida

ASKER

thamks man
this is working. now i`m going to make the case more and more complex to see how far i can make it. i hope i`ll do it right on my own.


ron
Avatar of Jason C. Levine
Good job, Rouchie!  There is hope for you yet.

Ron,  next time all you need to do is place the radio button or checkbox on the page and select it.  In the Properties Panel, click the lightning bolt and make it a dynamic radio/checkbox.  

DW would have written the code for you.
Avatar of derrida

ASKER

hi jason

i know that DW will do it for me. the thing is that i found out that it do too much for me and inorder to improve my control over php i began to write myself things.
its always tempting to let DW to do the job but i found out that at least when you learn the language it is preferable to do it by hand, i`m learning much more.

best regards

ron
Ron,

By all means, learn how to do it by hand!  I applaud you for trying and if you remember what your earlier questions were like, you've come a long way in a short time :)
Avatar of derrida

ASKER

hi
thanks i hope so:)
although sometimes i do feel very stupid when not doing simple things. but i hope its just the learning curve.

best regards

ron
It's just the learning curve.  We all had to climb it.
>> Good job, Rouchie!  There is hope for you yet.

What part of "not in this lifetime" .... (!)  ;-)

>> i found out that it do too much for me and inorder to improve my control over php i began to write myself things.

Well said Ron.  I hope more developers would learn a lesson from you!
>> I hope more developers would learn a lesson from you!

Especially if that lesson is "learn PHP"