need to change radio inputs to dropdowns...

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
glennn3
Forum Commoner
Posts: 63
Joined: Sat Sep 20, 2003 8:43 pm

need to change radio inputs to dropdowns...

Post by glennn3 »

kind folks - i'm still learning this wonderful language but have an issue i need to overcome a little more quikly than i can do myself - these are the ways i learn this stuff anyway...

i need to turn these radio buttons into dropdowns, can someone please get me started so i can see what needs to be done? --->

Code: Select all

<?
	$inceput=5*$indice;
	$query="select DISTINCT question.id,question.questions from question,responses where question.id=responses.id_questionsorder by question.ordine LIMIT $inceput,5";
	$resultQuestion=mysql_query($query) or die($query. mysql_error());
	$nQuestion=mysql_num_rows($resultQuestion);
	if ($nQuestion)
	{
?>
<div align="center"><center><table border="0" width="96%">
<form name="inscriere" action="add_question.php" method="post">
<input type="hidden" name="id" value="<?=$id?>">
<input type="hidden" name="indice" value="<?=$indice?>">
<tr><td height="5">&nbsp;</td></tr>
<? 
	for($i=0;$i<$nQuestion;$i++)
	{
		$item=mysql_fetch_object($resultQuestion);
?>
<tr><td><strong><?=$item->questions?></strong></td></tr>
<?
	$query="select * from responses where id_questions=$item->id";
	$resultResponses=mysql_query($query) or die($query. mysql_error());
	$nResponses=mysql_num_rows($resultResponses);
	for($j=0;$j<$nResponses;$j++)
	{
		$data=mysql_fetch_object($resultResponses);
?>
<tr><td valign="top">
<input type="radio" name="questions<?=$item->id?>" value="<?=$data->id?>" <?=(isset(${questions.$item->id}))?"CHECKED":""?>><?=$data->raspuns?>
</td></tr>
<tr><td valign="top">
<br>
<br> 
 </td></tr>
<?
	}
?>
<tr><td height="5">&nbsp;</td></tr>
<?
	}
?>
i very much appreciate it...

g
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Code: Select all

...
   for($j=0;$j<$nResponses;$j++)
   {
      $data=mysql_fetch_object($resultResponses);
?>
<tr><td valign="top">
<input type="radio" name="questions<?=$item->id?>" value="<?=$data->id?>" <?=(isset(${questions.$item->id}))?"CHECKED":""?>><?=$data->raspuns?>
</td></tr>
<tr><td valign="top">
<br>
<br>
</td></tr>
<?
  	}
...
is the part of the code that generates the radio buttons.
One difference between radio buttons and dropdowns is that radio buttons are grouped by having the same name while dropdowns are encapsulated by an element that carries the name-property.
Instead of

Code: Select all

&lt;input type="radio" name="questions111" value="whatever1"&gt;rama
&lt;input type="radio" name="questions111" value="whatever2"&gt;lama
&lt;input type="radio" name="questions111" value="whatever3"&gt;dingdong
you need

Code: Select all

&lt;select name="questions111&gt;
	&lt;option value="whatever1"&gt;rama&lt;/options&gt;
	&lt;option value="whatever2"&gt;lama&lt;/options&gt;
	&lt;option value="whatever3"&gt;dingdong&lt;/options&gt;
&lt;/select&gt;
try

Code: Select all

...
?>
	<tr><td valign="top">
		<select name="questions<?=$item->id?>">
<?php
   for($j=0;$j<$nResponses;$j++)
   {
      $data=mysql_fetch_object($resultResponses);
?>
			<option value="<?=$data->id?>" <?=(isset(${questions.$item->id}))?'SELECTED="SELECTED"':''?>>
				<?=$data->raspuns?>
			</options>
<?php
  	}
?>
		</select>
  </td></tr>
...
(tested not even by compiler)
glennn3
Forum Commoner
Posts: 63
Joined: Sat Sep 20, 2003 8:43 pm

Post by glennn3 »

right - thanks, i see - i was actually very close in my efforts; i knew i had to get part of the code within the select because i was repeating an entire select for each choice instead of getting the options to repeat... thanks for your help.

g
glennn3
Forum Commoner
Posts: 63
Joined: Sat Sep 20, 2003 8:43 pm

Post by glennn3 »

with a little tweakinf that worked fabulously - thanks, volka.
Post Reply