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

  • Home
  • SEARCH
  • 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 3433842
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:37:33+00:00 2026-05-18T07:37:33+00:00

Have just come across a problem where I believe this is the solution. At

  • 0

Have just come across a problem where I believe this is the solution.

At the moment I have the following code:

function siteUsers()
{
    global $database;
    $q = "SELECT username, id FROM ".TBL_USERS."";
    return mysql_query($q, $this->connection);
}

function generateUserArray() 
{
    $u = array();
    $i = array();
    $result = $this->siteUsers();
    while( $row=mysql_fetch_assoc($result)) 
    {
        $u[] = $row['username'];
        $i[] = $row['id'];
    }
    return $u, $i;
}

As you can see, when I then go onto use foreach, the $u and $i get split apart.
Is there anyway that I could keep them together?

foreach ($u as $username) {
    echo"<option value='$i'>$username</option>";
}

What I need it the option value to be the id and the visual value to be the username.
Is this possible?

  • 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-18T07:37:33+00:00Added an answer on May 18, 2026 at 7:37 am

    Use an associative array linking the ID to the username. I’m assuming here the IDs are unique.

    $users = array();
    while( $row=mysql_fetch_assoc($result)) 
    {
        $users[$row['id']] = $row['username'];
    }
    return $users;
    

    Then:

    foreach ($users as $id => $username)
    {
        echo "<option value='$id'>$username</option>";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've just come across a database where all the character based columns have their
Here's an interesting problem that I have just come across. It is possible to
I have a database which has almost 300 tables, I've just come across with
I've been working on this application but have come across a problem that I
I have just come across a Visual C++ option that allows you to force
Members at work have come across a C# project posted on Google code that
I've been experimenting with ASP.Net MVC, and have come across a problem that is
I have just come across something that is quite strange and yet I haven't
I come across this problem when i am writing an event handler in SharePoint.
I've just come across this in a WHERE clause: AND NOT (t.id = @id)

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.