Jump to content


Photo

from DB to Form to update a record


  • Please log in to reply
2 replies to this topic

#1 ScorpionX

ScorpionX
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 04 May 2006 - 12:37 PM

hi people,

i got this DB and form.

the form is used to insert data in the database,
but now i want with the same kinda form to update the records.

so i need to extract the data from the DB and insert them into the form.

with a few textboxes this is no problem example:
<input type="text" name="input1-7" value="<?PHP printf("mysql_result($result,0,"Lastname")) ?>"/>

but when i got a group of radiobuttons i know how to get them checked(in html), like this:

<input type="radio" name="RadioGroup1" value="1" /> 
<input type="radio" checked="checked"name="RadioGroup1" value="2" />

but i have no idea how to do this when i got a value like "2" how do i get the right one checked?

i know it should be possible if u do somethin like this(just an example, wont work exactly like this)

<input type="radio" <?PHP IF ("mysql_result($result,0,"value")) = = "2"{print "checked=checked" ?> name="RadioGroup1" value="2" />

but this would be 2 much work, cause i have a lot of radiobuttons...

is there anyone who could help me with this problem?

thnx for your time!

greetz Scorp.


#2 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 04 May 2006 - 01:11 PM

You need to create a loop that will build the radio button groups for you. The name of the group stays the same, and as long as the values are fairly uniform, you can put an if statement inside the for loop to check to see if the database value is equal to the loop value and if it is, echo the checked part, otherwise don't.

Info: PHP Manual


#3 ScorpionX

ScorpionX
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 04 May 2006 - 01:31 PM

[!--quoteo(post=371239:date=May 4 2006, 03:11 PM:name=ober)--][div class=\'quotetop\']QUOTE(ober @ May 4 2006, 03:11 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
You need to create a loop that will build the radio button groups for you. The name of the group stays the same, and as long as the values are fairly uniform, you can put an if statement inside the for loop to check to see if the database value is equal to the loop value and if it is, echo the checked part, otherwise don't.
[/quote]

ok,

thnx i will try that ^^




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users