• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 174
  • Last Modified:

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
0
derrida
Asked:
derrida
  • 7
  • 6
  • 4
1 Solution
 
RouchieCommented:
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... :-)
0
 
derridaAuthor Commented:
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
0
 
RouchieCommented:
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>
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
derridaAuthor Commented:
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
0
 
RouchieCommented:
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>
0
 
derridaAuthor Commented:
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
0
 
RouchieCommented:
Have you correctly used either the double or triple equals sign (== or ===) that compares values and types?
0
 
derridaAuthor Commented:
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
0
 
RouchieCommented:
Actually I made a mistake there, sorry.  You don't need a value if you're not posting the form on after it has been filled out.  A very silly mistake on my behalf.  Checked also does not have a value in HTML, so we can miss that bit out.

<td>
      <label>is he an actor:</label>
</td>
<td>
      <input name="radio3" type="checkbox"
            <?php
            if ($row_peopleQ['people_isactor']==1)
                  {
                  echo "checked";
                  }
            ?>
       />
</td>
0
 
derridaAuthor Commented:
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
0
 
Jason C. LevineNo oneCommented:
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.
0
 
derridaAuthor Commented:
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
0
 
Jason C. LevineNo oneCommented:
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 :)
0
 
derridaAuthor Commented:
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
0
 
Jason C. LevineNo oneCommented:
It's just the learning curve.  We all had to climb it.
0
 
RouchieCommented:
>> 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!
0
 
Jason C. LevineNo oneCommented:
>> I hope more developers would learn a lesson from you!

Especially if that lesson is "learn PHP"
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

  • 7
  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now