Solved

problem presenting dynamic php data in a non-text elements

Posted on 2007-03-21
17
155 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

 
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
 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Adobe Dreamweaver CS5 is a WYSIWYG web page editor that has advanced HTML, CSS, and Javascript rendering functionality and is probably the most well-known HTML editor available. Much of Dreamweaver's appeal centers around the Design View interfac…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

749 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