Solved

problem presenting dynamic php data in a non-text elements

Posted on 2007-03-21
17
152 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
ID: 18762690
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
ID: 18762849
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
ID: 18762940
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
ID: 18762958
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
ID: 18762995
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
ID: 18763018
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
ID: 18763088
Have you correctly used either the double or triple equals sign (== or ===) that compares values and types?
0
 
LVL 1

Author Comment

by:derrida
ID: 18763135
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 25

Accepted Solution

by:
Rouchie earned 50 total points
ID: 18763207
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
ID: 18763823
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
ID: 18766432
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
ID: 18769365
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
ID: 18769446
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
ID: 18769474
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
ID: 18769566
It's just the learning curve.  We all had to climb it.
0
 
LVL 25

Expert Comment

by:Rouchie
ID: 18769749
>> 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
ID: 18773063
>> I hope more developers would learn a lesson from you!

Especially if that lesson is "learn PHP"
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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 …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

911 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

15 Experts available now in Live!

Get 1:1 Help Now