简体   繁体   中英

Creating a unique radio button for each SQL result row

I would like to create a radio button that will have a unique roomCode as a selecter based on each row. So if the roomCode = 1, the unique identifier within that row will be 1. This is so I can then submit a radio button to bring up a timetable based upon the roomCode selected.

Here is my PHP code:

$numeroOption = $_POST['numero'];
$roomtype = $_POST['roomtype'];
$selectOption = $_POST['parkname'];
$query = "SELECT * FROM `ROOMS` WHERE `Capacity` < '$numeroOption' AND `Park` LIKE '$selectOption%' AND `dataProjector` LIKE '$proj_check%' AND `Whiteboard` LIKE '$white_check%' AND `OHP` LIKE '$ohp_check%' AND `WheelchairAccess` LIKE '$wheel_check%' AND `lectureCapture` LIKE '$cap_check%' AND `Style` LIKE '$roomtype%'"; 
$result = mysql_query($query);

if ($result == FALSE) 
    die ("could not execute statement $query<br />");

echo "<table>"; 
while($row = mysql_fetch_array($result))
{   
    echo "<tr><td>" . $row['roomCode'] . "</td><td>" . $row['Park'] . "</td><td>" . $row['Capacity'] . "</td><td>" . $row['Style'] . "</td><td>" . $row['dataProjector'] . "</td><td>" . $row['Whiteboard'] . "</td><td>" . $row['OHP'] . "</td><td>" . $row['wheelchairAccess'] . "</td><td>" . $row['lectureCapture'] . "</td></tr>";
}
echo "</table>"; 
mysql_close(); 
}

For starters, you should be using mysqli or PDO. PDO is best if you will be using multiple databases (mysql and sql, etc) but if not, I prefer mysqli because i feel its more efficient.

To solve your problem...

    <form>
      while($row = mysql_fetch_array($result))
      { 
          echo "<tr><td><input type="radio" name="radioSelect" value= "" checked="" /></td><td>" . $row['roomCode'] . "</td><td>" . $row['Park'] . "</td><td>" . $row['Capacity'] . "</td><td>" . $row['Style'] . "</td><td>" . $row['dataProjector'] . "</td><td>" . $row['Whiteboard'] . "</td><td>" . $row['OHP'] . "</td><td>" . $row['wheelchairAccess'] . "</td><td>" . $row['lectureCapture'] . "</td></tr>";
    }
     }
    <input type="submit"/>
    </form>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM