radio buttons

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
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

radio buttons

Post by aceconcepts »

Hi,

I have created a page that displays a list extracted from a mysql db. In each row i have a radio button.

When I view the page i am able to select all radio buttons. I would like to be able to just select one so if i try to select multiple radio buttons i can't, just the current one i have selected.

Thanks.
walkekev
Forum Newbie
Posts: 4
Joined: Wed Mar 22, 2006 7:38 pm

Post by walkekev »

give me an example
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Post by aceconcepts »

http://www.lastminute.com/

On the home page there is a box titled 'Search by category'.

Notice that you cannot select more than one radio button.

How can I do this using php?

Thanks.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

name them all exactly the same and they will automaticaly group together.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Post by aceconcepts »

This is how i have coded my list:

Code: Select all

<?php
//include "auth.inc.php";
//include "b2b_header.php";
//CONNECT TO SERVER AND DATABASE
session_start();
include "conn.inc.php";

$query = "SELECT * FROM delivery" ;

$result = mysql_query($query)
	or die(mysql_error());
?>
<html>
<body>
<table width="600" border="0">
  <tr bgcolor="#0099CC"> 
    <td width="414"><strong><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">Destination</font></strong></td>
    <td width="103"> 
      <div align="center"><font color="#FFFFFF"><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Duration</font></strong></font></div></td>
    <td width="103"> 
      <div align="center"><font color="#FFFFFF"><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Price</font></strong></font></div></td>
    <td width="83"></td>
  </tr>
  <?php 
 while ($row = mysql_fetch_array($result)) {
	extract($row);
  echo "<tr bgcolor=\"#CAE0EE\"><td><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">";
  echo $del_destination;
  echo "</font></td>";
  echo "<td align=\"center\"><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">";
  echo $del_duration;
  echo "</td></font>";
  echo "<td align=\"center\"><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">";
  echo $del_price;
  echo "</td>";
  echo "<td align=\"center\"><br>";
?>
  <form name="form1" method="post" action="">
    <input type="radio" name="radiobutton" value="radiobutton">
  </form>
  <?php
 echo "</td></tr>";
  }
  ?>
</table>
</body>
</html>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the form should span all the radio buttons. i.e. start before the table starts, and end after the table does.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Post by aceconcepts »

wonderful!!!!

Thanks a lot for your help. Once again.
Post Reply