Radio Buttons and Database Results

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jspight
Forum Newbie
Posts: 2
Joined: Sat Mar 18, 2006 9:39 am

Radio Buttons and Database Results

Post 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]
User avatar
William
Forum Contributor
Posts: 332
Joined: Sat Oct 25, 2003 4:03 am
Location: New York City

Post 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.
jspight
Forum Newbie
Posts: 2
Joined: Sat Mar 18, 2006 9:39 am

Reply to Update

Post 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?
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Code: Select all

<?php

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

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

echo ">";
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

I believe for checkboxes and radio buttons it's "checked", and "selected" is for select boxes.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply