similar_text, mysql prob

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!


I was wondering if anyone here had a decent solution to this mysql/php

I have a mysql database with a list of groups (group_id, group_name,
group_location, group_time, group_day). group_name must be unique for
each group_location - so there is only ever one particular group name
per group location.

I want to let users join a group or add a new group as they please. The
user is provided with a form to fill out group_name, group_location,
group_time, group_day and they post the form to a php page that checks
what groups are in a particular location.

I want to provide to the user information in this order:
1.)exact group_name match if there is one (showing the details of the group)
2.)the group information they provided in the posted form if there are
no exact matches
3.)close group_name matches if there are some (showing the details of
the group)

This is an intuitively ordered list and makes it all the more user friendly.

So after the user posts the form page to the checking page, I have a
query that selects the group_id of the group_name they selected:

$query_group = "SELECT group_name FROM groups WHERE group_id  =

Then I do a while loop with $row = mysql_fetch_array($query_group) and
have an if then else for various options:

$row['group_name'] = $_POST['group_name']
$row['group_name'] = $_POST['group_name']

and for similar text:
similar_text(strtoupper($group_name), strtoupper($row['group_name']),

Where I show similar matching group_names if
(number_format($similarity_pst, 0) > 90){

Of course this is all out of order if the first row is similar matching
then it shows the similar match before a later exact match in the mysql

How do I get a well-ordered output as indicated above? I don't want a
lot of nested queries to achieve it (one query for exact, one query for
LIKE and no match). Is there an elegant solution? Maybe dump out all
groups for the specified group_location and push the matching score onto
the array and sort?? Or maybe a temp table - no idea, never used that in

I would also like to use the better string comparison power of
similar_text or even levenshtein in php.

Help much appreciated.



Site Timeline