Forum Moderators: coopster

Message Too Old, No Replies

Building search parameters from a mysql db

Building search parameters from a mysql db

         

shdwmage

7:19 pm on Aug 29, 2008 (gmt 0)

10+ Year Member



Good Afternoon!

Let me start with a bit of a preface of my problem here.
I have a site with a decent amount of data stored into a mysql backend.

I have built a search engine to be able to search this information and be able to show it to the customer, but I have been forced to hand code all of the different options.

I would like to be able to code it to populate the information from the fields that are already in the database. I can code this part ok, the problem I am having is that I am getting all the duplicate information.

I want to know how to just include the first of every duplicate. So for example if I wanted to do a search for John and I had like 10 different Johns in the db the search list would only show John or Jon, not John 10 times in a row.

Any help would be greatly appreciated!

----
As far as your curiosities, I come from a programming background, but have self-taught myself MySQL and PHP.

eelixduppy

7:24 pm on Aug 29, 2008 (gmt 0)



Hello and Welcome to WebmasterWorld! :)

If the entries are the same you can SELECT DISTINCT which will not have duplicates.

Refer to the select syntax here: [dev.mysql.com...]

shdwmage

7:34 pm on Aug 29, 2008 (gmt 0)

10+ Year Member



Thank you, so the syntax of the query would be something along the lines of:

SELECT DISTINCT name FROM database WHERE valid='yes' limit X

Thanks for the quick response.

shdwmage

7:44 pm on Aug 29, 2008 (gmt 0)

10+ Year Member



Alright just running the next step by you as well:


$query = "select distinct name from db where valid='yes'";
$result = mysql_query($query);
while($row=mysql_fech_array($result, MYSQL_NUM))
{
$output .= "<option value='" . $row[0] . "'>" . $row[0] . "</option>";
}

Thanks again for the input.

--- edit: missed a close quote

eelixduppy

8:09 pm on Aug 29, 2008 (gmt 0)



Alright, at a quick glance it looks OK. Did you try it? What were the results?

shdwmage

8:25 pm on Aug 29, 2008 (gmt 0)

10+ Year Member



I'm not going to do any more coding at work today. It will sit on my note pad until I come in Tuesday morning, but I'm pretty sure that will work, I just ninja-d part of a different code I had already written to make a quick list of the names.

I will let you know if it doesn't.

Thanks again.

shdwmage

8:14 pm on Sep 2, 2008 (gmt 0)

10+ Year Member



Worked like a charm, just thought I would hop back on and say it worked, and thanks again.

Now off to code some other things. I feel so underpaid lol.