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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:40:19+00:00 2026-05-24T17:40:19+00:00

what is the best, tidiest way to populate a html select tag with items

  • 0

what is the best, tidiest way to populate a html select tag with items from the database?

For example, if I have the following php:

  $sql="SELECT a.athleteId, a.fName, a.lName FROM Athletes a, SupportStaff s, StaffAthletes sa WHERE sa.staffId = $id AND a.athleteId = sa.athleteId"; 
  $result=mysql_query($sql);

Then:

  1. How do I populate the drop down menu with the list of tuples retrieved from the relation?
  2. How should the php, html and jQuery be integrated?

I have the following, but it doesn’t work- It just displays a blank page:

<?php
error_reporting(E_ALL)
session_start();
//connect to database
function connect() {
  $dbh = mysql_connect ("localhost", "d", "a") or die ('I cannot connect to the database because: ' . mysql_error());
  mysql_select_db("PDS", $dbh); 
  return $dbh;
}

if(isset($_SESSION['username'])){
  $dbh = connect();
  $id = $_SESSION['id'];
  $sql="SELECT a.athleteId, a.fName, a.lName FROM Athletes a, SupportStaff s, StaffAthletes sa WHERE sa.staffId = $id AND a.athleteId = sa.athleteId"; 
  $result=mysql_query($sql); 

  $options="";   
  $i = 1;
  while ($row=mysql_fetch_array($result)) { 
    $f=$row["fName"]; 
    $l=$row["lName"]; 
    $options.="<OPTION VALUE=\"$i\">".$f.' '.$l."</OPTION>"; 
    $i++;
  }
?>

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
   <head>
   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
   <script src = "jQuery.js"></script>
   <script>
   $(document).ready(function(){
       $("#go").click(function(e){
       if($("#selectathlete option:selected").val() == "0"){
         alert("Please Select An Athlete");
       }else{
         //set hidden textfield
         $("form#profile").submit();
       }
       });
   });
  </script>
  <title>Personal Diary System - Home Page</title>
  </head>
  <body>
  <h1>Home Page</h1>
  <p>Select An Athlete: 
  <SELECT ID ="selectathlete" NAME="athletes"> 
  <OPTION VALUE="0">Choose</OPTION>
  <?php echo($options);?>
  </SELECT>
  </p>
  <form id = "profile" name="input" action="viewathleteprofile.php" method="post">
  <input type = "hidden" id = "athleteId">
  <input type = "button" name = "go" id = "go" value = "Go">
  </form>
  </body>
</html>

I’ve been debugging for hours and it just doesn’t work…

  • 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-24T17:40:20+00:00Added an answer on May 24, 2026 at 5:40 pm
    1. You should try to error_reporting(E_ALL) your page, so that you can see any and all errors your page comes across.
    2. What’s connect()? did you mean mysql_connect()?
    3. (Kinda unrelated) You shouldn’t use mysql_* functions, use MySQLi (Good) or PDO (Awesome).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Best practices or tools for installing a SQL Server database I have a SQL
Best to use an example to describe the problem. Lets say I have a
Best way to illustrate my question is with this example code: class Item {}
Best to explain with an example: int RecordCount { return dataAdapter.getCount(); // database access
Best way to get notification in from gmail in C#, when new email is
Best way i can demonstrate is by example, if you go here and move
Best way to describe this is explain the situation. Imagine I have a factory
Best way to manage user requests for reading too many rows from a table
Best Practices for Speeing Up Your Web Site from Yahoo includes the following recommendation:
Best way to load seed data? I have an Author table that is tightly

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.