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 6602031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:49:43+00:00 2026-05-25T18:49:43+00:00

I have a while loop that populates a dropdown box with values from a

  • 0

I have a while loop that populates a dropdown box with values from a mysql table. There are only two matching records and it is repeating them over and over. How do i only display each record once?:

$query = "SELECT * FROM members, sportevents, dates, results, event, userlogin ". 
         "INNER JOIN members AS m ON userlogin.id = m.id " .
         "WHERE userlogin.username = '$un' " . 
         "AND sportevents.id = members.id " . 
         "AND sportevents.event_id = event.id " .
         "AND sportevents.date_id = dates.id " .
         "AND sportevents.result_id = results.id";

echo "<form method='POST' action='display.php'>";
echo "Please Select Your Event<br />";
echo "<select name='event'>";
echo "<option>Select Your Event</option>";
$results = mysql_query($query)
    or die(mysql_error());
    while ($row = mysql_fetch_array($results)) {

    echo "<option>";
    echo $row['eventname'];
    echo "</option>";
                                               }

echo "</select>";
echo "<input type='submit' value='Go'>";
echo "</form>";
  • 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-25T18:49:44+00:00Added an answer on May 25, 2026 at 6:49 pm

    Have you tried running that query manually in the mysql monitor? Nothing in your code would produce an infinite loop, so most likely your query is not doing joins as you expect and is doing a cross-product type thing and creating “duplicate” records.

    In particular, your query looks very suspect – you’re using the lazy “from multiple tables” approach, instead of explicitly specifying join types, and you’re using the members table twice (FROM members ... and INNER JOIN members). You don’t specify a relationship between the original members table and the joined/aliased m one, so most likely you’re doing a members * members cross-product fetch.


    give that you seem to be fetching only an event name for your dropdown list, you can try eliminating the unused tables – ditch dates and results. This will simplify things considerable, then (guessing) you can reduce the query to:

    SELECT event.id, event.eventname
    FROM event
    INNER JOIN sportevents ON event.id = sportevents.event_id
    INNER JOIN members ON sportevents.id = members.id
    INNER JOIN userlogins ON members.id = userlogins.id
    WHERE userlogins.username = '$un'
    

    I don’t know if the members/userlogins join is necessary – it seems to just feed sportevents.id through to members, but without knowing your DB’s schema, I’ve tried to recreate your original query as best as possible.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a while loop that displays result from a MySQL query. I know
I have two simple while loops in my program that I feel ought to
Ok, so heres my question. I have a select dropdown that is populated from
i have a while loop that changes the id of each input field. print<td><input
I have a while loop that is going through and displaying an RSS icon
I have a simple while loop that checks the database for inserts. If its
I have read that while plug-ins are not supported for SQL Server Management Studio,
I'm trying to page a table, and while I have paging already working, it
I have two arrays built while parsing a text file. The first contains the
I have a table (venues) that stores all the possible venues a volunteer can

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.