LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-13-2005, 11:56 PM   #1
jabfinger
Member
 
Registered: Jan 2004
Location: USA, Pa
Distribution: Gentoo, Fedora Core 3, Mepis, Vector
Posts: 83

Rep: Reputation: 15
php radio button question


I have this code:

Code:
<?php
echo "<form method=\"post\" action=\"roster_process.php\" name=\"roster\">";
require_once "DB.php";
require_once "footballdb.php";
$conn =& DB::connect (fantasydb_dsn ());
if (DB::isError ($conn))
die ("Cannot connect to server");

$query1 ="CREATE TEMPORARY TABLE temp SELECT 
DISTINCT CONCAT(qb_stats.first_name,\" \",qb_stats.last_name) AS qb_name FROM qb_stats";
$result = mysql_query($query1) or die ("Query for qbtemp");
$query = "SELECT temp.qb_name FROM temp,members WHERE members.name=temp.qb_name 
AND members.owner=\"$owner\"";
$result = mysql_query($query) or die ("Query for QB");

//let's get the number of rows in our result so we can use it in a for loop
$numofrows = mysql_num_rows($result);
for($i = 0; $i < $numofrows; $i++) 
{
$row = mysql_fetch_array($result); //get a row from our result set
echo "<FONT SIZE=\"2\"><input name=\"qb_group\" 
value=".$row[0]." type=\"radio\">&nbsp;".$row[0]."</FONT><br>";
}
//now let's close the table and be done with it
"DROP TABLE temp";
$conn->disconnect ();

echo  "<input name=\"submit\" value=\"Enter\" type=\"submit\"></div>
</form>";
?>
Which is supposed to place qb_name's(first and last) next to radio buttons in a form. It is also supposed to send the selected qb_name(first and last) to another page (roster_process.php) when the Enter button is pressed.

The code for roster_process.php is this:

Code:
<html>
<head>
<body>
<?php
$qb_group = $_POST["qb_group"];
echo "$qb_group<br>";
?>
</body>
</head>
</html>
what happens is, on the form next to the radio buttons the first and last names of the desired qb's appear however on the roster_process.php page only the first name appears.

What is prohibiting both the first and last name of qb_name from being displayed on the roster_process.php page. I hope I have given enough detail about this problem for someone to be able to see the problem. The more I try to figure this out the less I understand.

Thanks.
 
Old 08-14-2005, 05:54 AM   #2
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
In the first code, change :
PHP Code:
...
echo 
"<FONT SIZE=\"2\"><input name=\"qb_group\" 
value="
.$row[0]." type=\"radio\"> ".$row[0]."</FONT><br>";
... 
to :
PHP Code:
...
echo 
"<FONT SIZE=\"2\"><input name=\"qb_group[]\" 
value="
.$row[0]." type=\"radio\"> ".$row[0]."</FONT><br>";
... 
And in roster_process.php, change :
PHP Code:
...
echo 
"$qb_group<br>";
... 
to :
PHP Code:
...
foreach(
$qb_group as $group) echo "$group<br>";
... 
 
Old 08-14-2005, 07:04 AM   #3
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
If you want to select multiple values then you'll need to use checkboxes instead of radio buttons as well as making the changes keefaz mentioned above.
 
Old 08-14-2005, 09:26 AM   #4
jabfinger
Member
 
Registered: Jan 2004
Location: USA, Pa
Distribution: Gentoo, Fedora Core 3, Mepis, Vector
Posts: 83

Original Poster
Rep: Reputation: 15
Thanks guys, for the reply.

Keefaz,

I corrected the code as you instructed but I get the same results, "first_name" only for the
roster_process.php page and "first_name last_name" for the originating roster.php page. I can not understatd this. It seems to me that ".$row[0]." should contain the exact same data for both instances.


 
Old 08-14-2005, 09:52 AM   #5
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
I think I see what you are meaning now. You need to escape the value in quotes - change:
value=".$row[0]."
to:

value=\"".$row[0]."\"
 
Old 08-14-2005, 10:36 AM   #6
jabfinger
Member
 
Registered: Jan 2004
Location: USA, Pa
Distribution: Gentoo, Fedora Core 3, Mepis, Vector
Posts: 83

Original Poster
Rep: Reputation: 15
thanks again for the reply,

david_ross,

You fixed it. It works as should. I am now confused by the fact that the old code placed the first_name on the roster_process.php page. Why did it place anything there at all? The code as it is now has two sets of .$row[0]. one with double quotes(escaped) and one with single quotes. They dont act the same way. If I place double quotes(escaped) on both, I end up with quotes around the name on the originating page but not on the roster_process page.

Anyway thanks for fixing this for me and if you have the time mabey you could clear up my question as well.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Segmentation Fault after adding a radio button into my compiled app/ Gnarg Programming 2 10-18-2005 06:47 AM
Internet Radio Question thewestwindow Linux - Software 1 10-04-2005 09:19 AM
[javascript] confirm button on php page Erhnam Programming 1 02-24-2005 01:05 PM
Question on Affero (thanks button) vharishankar LQ Suggestions & Feedback 2 01-09-2005 07:25 PM
X-Net Radio! Internet Radio with an attitude! xnetradio General 1 01-11-2004 11:01 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:31 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration