Solved

problem presenting dynamic php data in a non-text elements

Posted on 2007-03-21
17
151 Views
Last Modified: 2010-04-25
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
Comment
Question by:derrida
  • 7
  • 6
  • 4
17 Comments
 
LVL 25

Expert Comment

by:Rouchie
Comment Utility
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
 
LVL 1

Author Comment

by:derrida
Comment Utility
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
 
LVL 25

Expert Comment

by:Rouchie
Comment Utility
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
 
LVL 1

Author Comment

by:derrida
Comment Utility
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
 
LVL 25

Expert Comment

by:Rouchie
Comment Utility
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
 
LVL 1

Author Comment

by:derrida
Comment Utility
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
 
LVL 25

Expert Comment

by:Rouchie
Comment Utility
Have you correctly used either the double or triple equals sign (== or ===) that compares values and types?
0
 
LVL 1

Author Comment

by:derrida
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 25

Accepted Solution

by:
Rouchie earned 50 total points
Comment Utility
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
 
LVL 1

Author Comment

by:derrida
Comment Utility
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
 
LVL 70

Expert Comment

by:Jason C. Levine
Comment Utility
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
 
LVL 1

Author Comment

by:derrida
Comment Utility
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
 
LVL 70

Expert Comment

by:Jason C. Levine
Comment Utility
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
 
LVL 1

Author Comment

by:derrida
Comment Utility
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
 
LVL 70

Expert Comment

by:Jason C. Levine
Comment Utility
It's just the learning curve.  We all had to climb it.
0
 
LVL 25

Expert Comment

by:Rouchie
Comment Utility
>> 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
 
LVL 70

Expert Comment

by:Jason C. Levine
Comment Utility
>> I hope more developers would learn a lesson from you!

Especially if that lesson is "learn PHP"
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

For those who don't know, Adobe Dreamweaver is a popular commercial web editor that enables you to design, build and manage complex websites. The editor is a WYSIWYG (What You See Is What You Get) web editor, which means that you can create your web…
I still run into .cgi files every now and then. In some instances, I actually prefer the simplicity of a .cgi script to other options. Since I use DreamWeaver extensively, what I needed was a way to open .cgi scripts in Dreamweaver. And I wanted to …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now