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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:34:35+00:00 2026-06-10T15:34:35+00:00

I am trying to fillup two select boxes using the result of a mysql

  • 0

I am trying to fillup two select boxes using the result of a mysql select query. I run the query once and use the output variable to loop and set options of select tag accordingly. The problem is, first select box gets populated as expected but the second one does not. It remains empty whatsoever. Heres my code

    <?php

    $con = mysql_connect('localhost','root','') or die('Could Not Connect'.mysql_error());
    mysql_select_db('irctc', $con)or die('Could Not Select'.mysql_error());;
    $result = mysql_query("select * from stationcodes", $con)or die('Could not select'.mysql_error());
    ?>
    <html>
    <head>
    </head>
    <body>
        <table>
            <tr>
                <td>Source</td>
                <td>:-</td>
                <td><select id='src'>
                    <option value=''>Select Source Station</option>
                    <?php  while($row = mysql_fetch_array($result))
                    { ?>
                        <option value='<?php echo $row['StationCode']; ?>'><?php echo $row['StationName']; ?></option>
                    <?php } ?>
                    </select>
                </td>
            </tr>
            <tr>
                <td>Destination</td>
                <td>:-</td>
                <td><select id='dst'>
                    <option value=''>Select Destination Station</option>
                    <?php  while($row = mysql_fetch_array($result))
                    { ?>
                        <option value='<?php echo $row['StationCode']; ?>'><?php echo $row['StationName']; ?></option>
                    <?php } ?>
                    </select>
                </td>
            </tr>
        </table>
    </body>
    </html>
  • 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-06-10T15:34:37+00:00Added an answer on June 10, 2026 at 3:34 pm

    You need to “rewind” data pointer back to the beginning before starting to iterate over the results again. Use mysql_data_seek(0); to do that, before building your “Destination”:

                <td><select id='dst'>
                    <option value=''>Select Destination Station</option>
                    <?php  mysql_data_seek(0);         // reset data pointer to 1st row
                           while($row = mysql_fetch_array($result))
                    { ?>
                        <option value='<?php echo $row['StationCode']; ?>'><?php echo $row['StationName']; ?></option>
                    <?php } ?>
                    </select>
                </td>
    

    Also do not use mysql_. Switch to mysqli_ or PDO. and it would help you to separate code from view and use any type of template engine (like Smarty)

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

Sidebar

Related Questions

I am trying to use NSUser Deafault in my application user have tp fillup
I am trying to run some shell scripts for Java by using commons exec
I'm basically trying to create a generic object in javascript that I can use
I am trying to use priority_queue, and program constantly fails with error message HEAP
I am trying to upload files to a web server using System.Net.WebClient.UploadFile but I
I am trying to find out what's the most optimized SQL Query to achieve
I'm having problems with my modal window positioning. I've been trying to use $(document).height()
i am trying to create a css layout using pixels and percentages. the reason
I'm trying to make a Core Data app in which when you select one
Trying to make a make generic select control that I can dynamically add elements

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.