Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7431879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:21:56+00:00 2026-05-29T09:21:56+00:00

I have a users table in a database, where the user enters a form

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T09:21:57+00:00Added an answer on May 29, 2026 at 9:21 am

    Can’t you just run 1 query?

    $query = "SELECT streamnumber, COUNT(id) AS cnt FROM users 
     WHERE streamnumber IN ('Stream1', 'Stream2', 'Stream3',
     'Stream4', 'Stream5', 'Stream6') 
     GROUP BY streamnumber ORDER BY streamnumber "; 
    $result = mysql_query($query) or die(mysql_error());
    $my_array=array();
    while($row = mysql_fetch_array($result1))
    {
      $my_array[$row["streamnumber"]] = $row["cnt"];
    }
    // now $my_array["Stream1"] contains count of 'Stream1' 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP form that enters data into my MySQL database. My primary
I have a User controller and User model. This model and associated database table
I have a form where the user enters their database information and can click
I have a user table in my mysql database that has a password column.
I have a postgres database with a user table (userid, firstname, lastname) and a
I have a database table where the user marks files to be downloaded. Subsequently,
I have a combobox bound to a database table. When the user inserts a
I have a simple database with two tables. Users and Configurations. A user has
I have a table, users, in an Oracle 9.2.0.6 database. Two of the fields
I have a search form field that I want to compare with multiple columns

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.