I have a users table in a database, where the user enters a form into a database. This includes multiple radio buttons. I want it so the number of similar radio buttons is displayed next to the corresponding form entry.
There are 8 radio choices, and I have a working solution, although this is not ideal:
mysql_select_db($database_name, $db) or die(mysql_error());
$query1 = "SELECT streamnumber, COUNT(id) FROM users WHERE streamnumber = 'Stream1' GROUP BY streamnumber ORDER BY streamnumber ";
$result1 = mysql_query($query1) or die(mysql_error());
$query2 = "SELECT streamnumber, COUNT(id) FROM users WHERE streamnumber = 'Stream2' GROUP BY streamnumber ORDER BY streamnumber ";
$result2 = mysql_query($query2) or die(mysql_error());
$query3 = "SELECT streamnumber, COUNT(id) FROM users WHERE streamnumber = 'Stream3' GROUP BY streamnumber ORDER BY streamnumber ";
$result3 = mysql_query($query3) or die(mysql_error());
$query4 = "SELECT streamnumber, COUNT(id) FROM users WHERE streamnumber = 'Stream4' GROUP BY streamnumber ORDER BY streamnumber ";
$result4 = mysql_query($query4) or die(mysql_error());
$query5 = "SELECT streamnumber, COUNT(id) FROM users WHERE streamnumber = 'Stream5' GROUP BY streamnumber ORDER BY streamnumber ";
$result5 = mysql_query($query5) or die(mysql_error());
$query6 = "SELECT streamnumber, COUNT(id) FROM users WHERE streamnumber = 'Stream6' GROUP BY streamnumber ORDER BY streamnumber ";
$result6 = mysql_query($query6) or die(mysql_error());
I have made a seperate query for each radio button, and then going to display information using this logic:
<?php
while($row = mysql_fetch_array($result1)){
echo "There are ". $row['COUNT(id)'] ." ". $row['streamnumber'] ." items.";
echo "<br />";
} ?>
<input style="width:5px;" type="radio" name="streamnumber" value="Stream1" id="StreamDates_0">
<label>Stream 1 - Module 1 + 2 - 21st - 23rd March, Module 3 - 19th - 20th April, Module 4 - 15th - 16th May 4</label>
This way I can use each count and name as the query specifies the streamnumber. I am wondering if there is an easier way to do this? I assume this will be to do with a more complex array but I cant quite put my finger on it.
Can’t you just run 1 query?