Hello,

Please excuse me.. I am sure I'm using some wrong terminology.

I have a column in my database called "subjects".

A list of subjects here could include up to 12 terms, seperated by commas and spaces, for example:

"Choral, Band, Jazz, Voice"

I would like to use the following form to filter the displayed results:

<form name="theform" action="membership.php">
<b>Find only members with the following subjects:</b><br>
<SELECT NAME="subjects" Size="1">
<option value="Choral">Choral</option>
<option value="Band">Band</option>
<option value="Orch">Orchestra</option>
<option value="Keys">Keyboard</option>
<option value="Guitar">Guitar</option>
<option value="GM">General Music</option>
<option value="History">History/Theory/Composition</option>
<option value="Research">Research</option>
<option value="Teacher Ed">Teacher Education</option>
<option value="Jazz">Jazz</option>
<option value="Voice">Voice</option>
<option value="Tech">Technlogy</option>

</SELECT>
<input type="submit" value="Go!">

and if I use the form to display "Band"... it will only show me results where "Band" is the first item listed in the record. In other words, it's too discriminating. If the record says "Choral, Band"... it won't turn in up my search.

Here's all the code:

<?
  function pparams($sort) {
    global $type, $name, $school, $preferred_address, $home_phone, $home_email, $level, $subjects;

echo $HTTP_SERVER_VARS['PHP_SELF'];
echo "?type=".htmlentities(urlencode($type));
echo "&name=".htmlentities(urlencode($name));
echo "&school=".htmlentities(urlencode($school));
echo "&preferred_address=".htmlentities(urlencode($preferred_address));
echo "&home_phone=".htmlentities(urlencode($home_phone));
echo "&home_email=".htmlentities(urlencode($home_email));
echo "&levels=".htmlentities(urlencode($levels));
echo "&subjects=".htmlentities(urlencode($subjects));
echo "&sort=".htmlentities(urlencode($sort));
  }

  if (!$sort) $sort="type";
?>

<form name="theform" action="membership.php">
<b>Find only members with the following subjects:</b><br>
<SELECT NAME="subjects" Size="1">
<option value="Choral">Choral</option>
<option value="Band">Band</option>
<option value="Orch">Orchestra</option>
<option value="Keys">Keyboard</option>
<option value="Guitar">Guitar</option>
<option value="GM">General Music</option>
<option value="History">History/Theory/Composition</option>
<option value="Research">Research</option>
<option value="Teacher Ed">Teacher Education</option>
<option value="Jazz">Jazz</option>
<option value="Voice">Voice</option>
<option value="Tech">Technlogy</option>
</SELECT>

&nbsp;<input type="submit" value="Go!">

</form>



<? MySQL_connect("localhost", 'xxxxxxxx', 'xxxxxxxxxx'); MySQL_select_db("membership");   ?> 

<? $query =
        "SELECT membership.type,membership.name,membership.school,membership.preferred_address,membership.home_phone,membership.home_email,membership.levels,membership.subjects
        FROM membership
        WHERE ((membership.type LIKE '$type%')
              and (membership.name LIKE '$name%')
   and (membership.school LIKE '$school%'))
   and (membership.preferred_address LIKE '$preferred_address%')
   and (membership.home_phone LIKE '$home_phone%')
   and (membership.home_email LIKE '$home_email%')
   and (membership.levels LIKE '$levels%')
   and (membership.subjects LIKE '$subjects%')
        ORDER BY membership.$sort";


$resultt = mysql_query($query);

// Determine the number of employees
$number = mysql_num_rows($resultt);

if ($number == 0) {
   print "Sorry, there were no records matching those criteria";
} else {
while ($row = mysql_fetch_object($resultt)) {
    $type=$row->type;
    $name=$row->name;
    $school=$row->school;
    $preferred_address=$row->preferred_address;
    $home_phone=$row->home_phone;
    $home_email=$row->home_email;
    $levels=$row->levels;
    $subjects=$row->subjects;

print "<tr><td>&nbsp;<font size=1>$type</font></td> <td><font size=1>$name</font></td> <td><font size=1>$school</font></td> <td><font size=1>$preferred_address</font></td> <td><font size=1>$home_phone</font></td> <td><font size=1>$home_email</font></td><td><font size=1>$levels</font></td><td><font size=1>$subjects</font></td></tr>";
   }
}

// Close the database connection
mysql_close();

?>

Thanks in advance...

~Wayne

    you are only searching the begining of the field because you forgot your open percent wildcard in your LIKE clause:

    you are doing:
    LIKE '$type%'

    you should do:
    LIKE '%$type%'

      Write a Reply...