Page 1 of 1

Radio Buttons and Database Results

Posted: Sat Mar 18, 2006 9:47 am
by jspight
feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I have been working 4 days to select radio buttons from my database with no luck.  Can anyone break down some simple code for radio buttons?  I have attached my code which does not return the selected value.  Thanks!

Code: Select all

<?php include("dbconfig.php");
if ($DESIGN_ID) { 
$result = mysql_query("SELECT * FROM DESIGN_TABLE WHERE dusername= '$session->username'AND DESIGN_ID = $DESIGN_ID",$link);
$myrow = mysql_fetch_array($result); 
echo "<tr><td bgcolor=#CCE5FF>Your Design Contact Method: <input type=radio  name=CONTACT_METHOD value=Web Conference <=$myrow[CONTACT_METHOD])  selected=\"selected\">";} 
else { echo "Sorry, no records were found!"; } ?>

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Sat Mar 18, 2006 10:10 am
by William

Code: Select all

<?php
	include("dbconfig.php");
	if($DESIGN_ID) { 
		$SQLq = mysql_query("SELECT * FROM `DESIGN_TABLE` WHERE `DUSERNAME` = '{$session->username}' AND `DESIGN_ID` = '{$DESIGN_ID}'");
		$data = mysql_fetch_array($SQLq);
		echo "<tr><td bgcolor=\"#CCE5FF\">Your Design Contact Method: <input type=\"radio\"  name=\"CONTACT_METHOD\" value=\"Web Conference {$data['CONTACT_METHOD']}\" selected=\"selected\"";
	} else {
		echo "Sorry, no records were found!";
	}
?>
I really don't understand the problem but I fixed a few problems with your code above. Tell me if it helps.

Reply to Update

Posted: Wed Mar 22, 2006 4:30 am
by jspight
Thanks for your response! What I need to know is how to return radio button values from my sql database? Using and if statement or ternary operator to select the radio button based on a field value. Maybe you have an example I can follow?

Posted: Wed Mar 22, 2006 4:55 am
by s.dot

Code: Select all

<?php

echo "<input type=\"radio\" name=\"someName\" value=\"1\" ";

if($data_from_db == 1){
   echo "checked";
}

echo ">";

Posted: Wed Mar 22, 2006 4:56 am
by s.dot
I believe for checkboxes and radio buttons it's "checked", and "selected" is for select boxes.