mysql - PHP Populate Dropdown with Unique SQL Values Quickly

259

I have a website I'm working on where I want to populate 3-5 (let's say 3 for now) drop down boxes with unique values from a specific column in an SQL database.

Let's say I have

first   last   city

As my 3 drop downs to be populated.

Right now, I am doing something along the lines in my PHP of

$query = "SELECT DISTINCT `first` FROM `profile` ORDER BY `first` ASC;";

$result = mysqli_query($connect, $query) 

while($row=mysqli_fetch_array($result))
{
    $options1=$options1."<option>$row[0]</option>";
}

I do this then, two more times, for 'last' and 'city', populating $options2 and $options3 respectively.

The issue is, my database is going to be rather large. 10-100 Million rows large. When I load my page, this page takes several minutes to load. Is there something I can do to speed this up, so my main page doesn't take several minutes to load?

People are also looking for solutions to the problem: javascript - JS: OpenWeatherMap API returns "undefinded" for parameter "rain.3h"

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.