473,669 Members | 2,480 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

radiobutton name unknown

5 New Member
Heya, I think I shot myself in the foot when I set this up

Overview: I have a dynamically generated page for listing pictures for a project I am working on for my boss. To put it simply...this is a picture approval page.

Each picture (belonging to a group) has two radio buttons and a submit button attached to it.

Since the number of photos listed for each group is unknown, the names of the yes and no radio buttons had to be uniquely generated....

thusly I used:
echo "<input type='radio' name='radio".$r adio."' value='yes'>Yes ";
echo "<input type='radio' name='radio".$r adio."' value='no'>No<b r>";
echo "<input type='submit' value='submit'> <br>";
inside of a loop so that the value of $radio increments by one each loop.
what I end up with is, the first yes/no radio buttons are named radio0, the second set named radio1, the third is radio2 and so on...
Here's my problem

using post, I cannot use $_POST['radio#''] since I do not know which of the radio buttons he will select. Is there a way I can run the $_POST['radio#''] through a loop to find one that is set?

OR
is there a way on the first page (with the radio buttons) I can create a variable that will take the yes or no buttons on behalf of the radio button and send it to the next page

Any thoughts? Your help is greatly appreciated.

Thanks
Oct 6 '06 #1
8 2690
ronverdonk
4,258 Recognized Expert Specialist
This should get you on your way:
[php]
foreach ($_POST as $key => $value) {
if ($value == 'yes')
$nr = substr($key, 5); // $nr = button no that has 'yes' value
}[/php]

Ronald :cool:
Oct 6 '06 #2
ldndude
5 New Member
ok...before you laugh at my code. I am a noob. a big noob.
Let me explain what I am doing and what I have so far. Maybe you know a better way to do this.

I am trying to create a php/mysql system to list pictures that we are applicable to various job titles. For example. "Chef" might have 4 pictures listed for it. "Bartender" might have 3 pictures and so on

I am trying to make a page that prints an <hr> followed by the career. Then I have it listing the urls (stored in a database) to pictures relating to that position, accompanied by the yes and no radio buttons and a submit button.

Here is the code (don't laugh, I am very new at this) that we've developed so far.

It works, but I still don't understand what I need to do to find out which radiogroup he selected and which value from the selected group he chose.
using $_POST
Here's my code (i can hear the snickering begin)

<?php


$sector = "Processing ";

include("dbinfo .inc.php");
mysql_connect($ host,$username, $password);
@mysql_select_d b($database) or die("Unable to select database");


$query="SELECT * FROM linkpool,career list WHERE linkpool.cid =

careerlist.cid AND careerlist.Sect or='".$sector." ' AND

careerlist.fini sh ='no' AND linkpool.yeno != 'yes' AND linkpool.yeno

!= 'no' ORDER by linkpool.cid ASC;";

$result=mysql_q uery($query);
$num=mysql_numr ows($result);

mysql_close();

//$i counting loop
$i = 0;

//$radio sets unique names of the radio button groups by incrementing
$radio = 0;

//cidchecker is to check for when the cid increases to put a hr tag in
$cidchecker = 0;

echo "<form action='yeno.ph p' method='POST'>" ;

while ($i < $num) {
$cid=mysql_resu lt($result,$i," cid");
$Title=mysql_re sult($result,$i ,"Title");//name of the career
$url=mysql_resu lt($result,$i," url");// url of the picture
$lid=mysql_resu lt($result,$i," lid");//id of table that holds lid, cid, url, yeno (yes or no), final (the final stands for final approval)

/* pending on the above query, the cid numbers skip. This makes sure that the cidchecker keeps up to date with the cid */
if ($cid > $cidchecker+1) {
$cidchecker = $cid-1;
}

/* a new cid number means we reached a new career title so I would like it to end the last table. Print the new career title. And start a new table */

if ($cid > $cidchecker) {
echo "</td></tr></table>";
echo "<hr><br>";
echo $Title;
echo "<table><tr><td >";
}

echo "<img src='".$url."' height='200'

width='200'>".$ cid."/".$cidchecker." <br>";
echo "<input type='radio' name='radio".$r adio."' value='yes'>Yes ";
echo "<input type='radio' name='radio".$r adio."' value='no'>No<b r>";
echo "<input type='submit' value='submit'> <br>";
echo "</td><td>";


/* sometimes a career has more than one picture to approve. This is to help control when the table starts and stops */

if ($cid > $cidchecker) {
$cidchecker++;
}

$i++;
$radio++;
}
echo "</form>";


?>

Please help. I am very limited in my php and mysql knowledge.


Thanks
Oct 6 '06 #3
ronverdonk
4,258 Recognized Expert Specialist
That is a lot of code. ANd since you did not put that code between code or php tags, it is almost unreadable. So I'll ignore it. The following is an example of how to test and set the buttons clicked. It is tested and you can run this to see how it works.
[PHP]
<?php
$radio_set = array(); // setup empty array
if (isset($_POST['_submit']) ) { // is form submitted?
foreach ($_POST as $key => $value) { // if so: check posted values
if (substr($key,0, 5) == 'radio' // check if field starts with 'radio'
AND $value == 'yes' ) { // and value set to 'yes'
$radio_set[] = substr($key, 5); // if so: store button no in array
}
}
// print all the buttons that are set to 'yes'
echo "<pre>The following radio buttons are set: <br>";
for ($i=0; $i<count($radio _set); $i++)
echo "radio button $i is set to YES <br>";
}
else {
echo '<form name="MyForm" action='.$_SERV ER['PHP_SELF']. ' method="POST">' ;
// generate 10 radio butons
for ($radio=0; $radio<10; $radio++) {
echo "Click button for radio$radio";
echo "<input type='radio' name='radio$rad io' value='yes'>Yes ";
echo "<input type='radio' name='radio$rad io' value='no'>No<b r>";
}
// used to check if form is submitted
echo "<input type='hidden' name='_submit' value=1>";
echo "<input type='submit' value='submit'> <br>";
echo "</form>";
}
?>[/PHP]

Ronald :cool:
Oct 7 '06 #4
ldndude
5 New Member
That is a lot of code. ANd since you did not put that code between code or php tags, it is almost unreadable. So I'll ignore it. The following is an example of how to test and set the buttons clicked. It is tested and you can run this to see how it works.
[PHP]
<?php
$radio_set = array(); // setup empty array
if (isset($_POST['_submit']) ) { // is form submitted?
foreach ($_POST as $key => $value) { // if so: check posted values
if (substr($key,0, 5) == 'radio' // check if field starts with 'radio'
AND $value == 'yes' ) { // and value set to 'yes'
$radio_set[] = substr($key, 5); // if so: store button no in array
}
}
// print all the buttons that are set to 'yes'
echo "<pre>The following radio buttons are set: <br>";
for ($i=0; $i<count($radio _set); $i++)
echo "radio button $i is set to YES <br>";
}
else {
echo '<form name="MyForm" action='.$_SERV ER['PHP_SELF']. ' method="POST">' ;
// generate 10 radio butons
for ($radio=0; $radio<10; $radio++) {
echo "Click button for radio$radio";
echo "<input type='radio' name='radio$rad io' value='yes'>Yes ";
echo "<input type='radio' name='radio$rad io' value='no'>No<b r>";
}
// used to check if form is submitted
echo "<input type='hidden' name='_submit' value=1>";
echo "<input type='submit' value='submit'> <br>";
echo "</form>";
}
?>[/PHP]

Ronald :cool:

Thanks...I will give this a try.
Just one more question about posting code. As you can already tell, I have no formal training and am just learning. You mentioned "And since you did not put that code between code or php tags"
What should I do to make it cleaner and easier to read for future postings?
Oct 7 '06 #5
ronverdonk
4,258 Recognized Expert Specialist
I see that byou put the quation between quote tags som it reads easier. For the same reason, if you want to show code you are requested to put it between tags, php, code or html. If you don't do that, you run the chance that members don't look at your request because the shown code looks messy. See the related entry in this forum link http://www.thescripts.com/forum/misc.php?do=bbcode

Ronald :cool:
Oct 7 '06 #6
ldndude
5 New Member
ohhhh
I should be putting my code using the quotation tag.

So, next time I should submit like this?
place code in here
Does it colour code it on it's own like yours did above?
Oct 7 '06 #7
ronverdonk
4,258 Recognized Expert Specialist
No, I used the php end /php tags. That colors the code:
green for commands, blue for variables, yellow for comments and red for literals and strings.

How's your button test doing?

Ronald :cool:
Oct 7 '06 #8
Aarchaic
2 New Member
Hello i have a simular problem and need help.

i have a database of 320 pictures that i have in a Mysql Database that looks like this.

Database: Eggcraft

Tables:

Egg_imgs ( Pic_id (int and PK), Pic_name(varcha r (255)), Pic_desc(varcha r(255)),Pic_ima ge(varchar(255) ) )

Egg_cat ( Cat_id (int PK), Cat_name (varchar(255)), Cat_desc (varchar(255)) )

Egg_ImgCat ( Cat_id (int PK), Pic_id (int PK), Pic_cat (varchar (255) PK ) )

Egg_prod ( Pro_id (int PK), Pic1_name (varchar(255)), Pic1_image (varchar(255)), Pic2_name (varchar(255)), Pic2_image (varchar(255)), Word_id (varchar(255)), Word_desc (varchar(255)), Pro_qty (int) )

Word database i need to construct still but this is the key elements i need to work on now.

I want to call up all my pictures and limit them to 30 pictures per page since i almost crashed my pc calling all 320 pictures in a moment of not thinking at all.
But i want to add a radio button to select a image and send it back to the produst array whether it be picture 1 or 2 depending on the kind of product.

once i selected the radio button and click the submit button it will put the image Name into the Pic#_name and Pic#_image fields.

here is my code so far...

[PHP]

<html>

<body>
<?php
$conn = mysql_connect(' localhost','roo t','')
or die ('Unable to connect!!');

mysql_select_db ('eggcraft')
or die ('Unable to connect to database!!');

$query = 'SELECT * from egg_imgs';
$result = mysql_query($qu ery)
or die ('Error in query: $query. ' . mysql_error ());

If (mysql_num_rows ($result) > 0)
{
echo '<table width=100% cellpadding=10 cellspacing=0 border=1>';
echo '<tr><td><b>ID </b></td><td><b>Image Name</b></td><td><b>Discr iption</b></td><td><b>Image </b></td><td><b>Selec t</b></td></tr>';

while($row = mysql_fetch_row ($result))
{
echo '<tr>';
echo'<td>' . $row[0] . '</td>';
echo'<td>' . $row[1] . '</td>';
echo'<td>' . $row[2] . '</td>';
echo'<td>' . "<img src= $row[3] width=50 height=50>" . '</td>';
echo '</tr>';
}
// If i put "<img src= imgs/$row[3] width=50 height=50>" in the code it doesnt display the picture
// Only the Url reference in the properties and that ends to be http://localhost/imgs and doesnt connect the file name to the string
// But if i leave it as it is now and put the file in my imgs folder it does show the picture its not a huge problem but its something i cant understand.
echo '</table>';
}
else
{
echo 'No Rows found!!';
}

mysql_free_resu lt($result);

mysql_close($co nn);

?>
</body>
</html>

[/PHP]

Thank you very much for your time.
Feb 14 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

11
7862
by: William Gill | last post by:
I am placing radiobuttons in a 4 X 4 matrix (using loops) and keep references to them in a 2 dimensional list ( rBtns ). It works fine, and I can even make it so only one button per column can be selected, by assigning each column to an intVar. In many languages a radiobutton has a property that can be directly read to see if it is selected on unselected. Tkinter radiobuttons don't seem to have any such property. Is there any way to...
0
4130
by: rodrigo | last post by:
I have a Asp.net table control that I dynamically add rows from a SQL database. Inside the table, I add radiobuttons and they all have different ID numbers according to BindChain() Looking In BindChain() Sub for the line: AddHandler Rb.CheckedChanged, AddressOf BindAssembly_Click
3
36175
by: sofie | last post by:
Hello all, I use the following javascript function in a html document to set the level of one of eight available radiobuttons. The line that's commented out works fine under IE, but I need to rewrite it so that it's W3C compliant. Reading through earlier messages I concluded I should go with getElementById but this doesn't work. What am I doing wrong? Your help is much appreciated.
2
1866
by: JeffFinnan | last post by:
<form name=form1> Load in Viewer Window: <input name="radiobutton" type="radio" value="1" checked onClick="1"> 1&nbsp;&nbsp;&nbsp; <input type="radio" name="radiobutton" value="2" onClick="2"> 2&nbsp;&nbsp;&nbsp; <input type="radio" name="radiobutton" value="3" onClick="3"> 3&nbsp;&nbsp;&nbsp; <input type="radio" name="radiobutton" value="4" onClick="4"> 4
3
7249
by: dave | last post by:
I have half a dozen web form radio buttons on a web form. Each of them is set to postback=true. However, if for instance radiobutton1 is already selected and the user selects it again, it performs a postback. I only want to do a postback if the value of the radiobutton is changed. What is the best method to accomplish this? thx dave
3
3065
by: visual2005beta_developer | last post by:
I have the following problem (especially with the groupname-attribut of the RadioButton-Control) when developing in Visual Studio 2005 Beta. I load an ascx-control in an aspx-page. This ascx-control itself creates dynamically many radiobuttons in this way: foreach (DataRow radiobutton_item in rbl_values.Rows) { RadioButton single_radiobutton = new RadioButton(); single_radiobutton.ID = "idname"; single_radiobutton.GroupName =...
8
7971
by: Agnes | last post by:
I create an array to store the radiobutton list. If the user click the 3rd buttons, I should store the value 2 into the table fields, My method is check each radio button whether is checked or not, if Me.rb1stbutton.checked than .. store 0 if Me.rb2..... checked then store 1 ......... if Me.rb6... checked then store 5. Any other simple method to know which button is checked ? thanks a lot
0
1294
by: member | last post by:
Hi, Good day.i need some help from you guys. I'm using vb.net and sql database to build my file. The purpose of this file is to view news based on deparment. Im using listbox and radiobutton list in this file. listbox- to get department names in sql table radiobutton - to get the headline news for the department name choosen
8
44028
by: =?Utf-8?B?UmljaA==?= | last post by:
If you enclose a group of radiobuttons (option buttons in MS Access) in an option group control (a frame control) in Access -- the frame control will return the index of the option button that is checked. In VB.Net if I enclose a group of radiobuttons in a groupbox control - I get the single checked radiobutton behavior, but the groupbox does not seem to return the index of the checked radiobutton. Is there a way to get the groupbox...
0
8383
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8895
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8809
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8588
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8658
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7407
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4206
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4386
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2032
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.