#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Copenhagen, Denmark
    Posts
    3
    Rep Power
    0
    Hi I'm really stuck with this problem: I'm having a Mysql database with two tables, one table person containing the personal information, and another table profile, with several columns that can be either y or n.

    As it is now, from a html form I can enter information in the database, and I edit a persons personal information and profile.

    But now I want to be able to find persons based on their profile, so I have a form with a checkbox for each column in the profile table. I want to be able to check off one or more checkboxes, and get the names and id number for the corresponding persons. But invariably I get all the persons in the database as a result. Even when I _don't check any boxes_!
    I include the code snippets here:

    The search string: notice I have tried to write profil.fabrik instead of p.fabrik etc, but no change in result.

    $sql2= "SELECT distinct person.id, person.navn, person.uddannelse FROM person, profil p WHERE p.fabrik = '$fabrik' OR p.service = '$service' OR p.analyse = '$analyse' OR p.born = '$born' OR p.okonomi = '$okonomi' OR p.undervis = '$undervis' OR p.edb = '$edb' OR p.pleje = '$pleje' OR p.xlate = '$xlate' OR p.salg = '$salg' OR p.butik = '$butik' OR p.kontor = '$kontor' OR p.hotel = '$hotel' OR p.turisme = '$turisme' OR p.tb = '$tb' OR p.tu = '1' OR p.ts = '$ts' OR p.db = '$db' OR p.du = '$du' OR p.ds = '$ds' OR p.rb = '$rb' OR p.ru = '$ru' OR p.rs = '$rs' OR p.dtpb = '$dtpb' OR p.dtpu = '$dtpu' OR p.dtps = '$dtps' OR p.hb = '$hb' OR p.hu = '$hu' OR p.hs = '$hs' OR p.sommer = '$sommer' OR p.kort = '$kort' OR p.fast = '$fast' AND profil.owner = person.id";

    $result2 = mysql_query ($sql2) ;

    if (mysql_numrows($result2) == 0)
    echo "No result<br>";

    else
    {

    $myrow = mysql_fetch_array($result2);

    while ($myrow = mysql_fetch_array ($result2))

    {
    printf ("<a href ="%s?id=%s">%s</a> %s<p>", $PHP_SELF, $myrow["id"], $myrow ["navn"], $myrow["uddannelse"]);

    }
    }

    The checkbox part:

    <form method="post" action="<?php echo $PHP_SELF?>">

    <table border="0" width="0%">
    <tr>
    <td >
    <input type="checkbox" name="fabrik" value="1">
    </td>
    <td>Fabrik &amp; Lager</td>
    <td >
    <input type="checkbox" name="pleje" value="1">
    </td>
    <td>Pleje &amp; Omsorg</td>
    </tr>
    <tr>
    <td>
    <input type="checkbox" name="service" value="1">
    </td>
    <td>Service &amp; Transport</td>
    <td>
    <input type="checkbox" name="xlate" value="1">
    </td>
    <td>Overs&aelig;ttelser</td>
    </tr>
    <tr>
    <td>
    <input type="checkbox" name="analyse" value="1">
    </td>
    <td>Analyse &amp; Udvikling</td>
    <td>
    <input type="checkbox" name="salg" value="1">
    </td>
    <td>Salg</td>
    </tr>
    <tr>

    .... SNIP

    Erik





  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2000
    Posts
    669
    Rep Power
    14
    Have you tried placing all the OR statements in parantheses like and the and also

    $sql2= "SELECT distinct person.id, person.navn, person.uddannelse FROM person, profil p WHERE ((p.fabrik = '$fabrik') OR (p.service = '$service') OR (p.analyse = '$analyse') OR (p.born = '$born') OR (p.okonomi = '$okonomi') OR (p.undervis = '$undervis') OR (p.edb = '$edb') OR (p.pleje = '$pleje') OR (p.xlate = '$xlate') OR (p.salg = '$salg') OR (p.butik = '$butik') OR (p.kontor = '$kontor') OR (p.hotel = '$hotel') OR (p.turisme = '$turisme') OR (p.tb = '$tb') OR (p.tu = '1') OR (p.ts = '$ts') OR (p.db = '$db') OR (p.du = '$du') OR (p.ds = '$ds') OR (p.rb = '$rb') OR (p.ru = '$ru') OR (p.rs = '$rs') OR (p.dtpb = '$dtpb') OR (p.dtpu = '$dtpu') OR (p.dtps = '$dtps') OR (p.hb = '$hb') OR (p.hu = '$hu') OR (p.hs = '$hs') OR (p.sommer = '$sommer') OR (p.kort = '$kort') OR (p.fast = '$fast')) AND (profil.owner = person.id)";

Similar Threads

  1. need SQL help - one query or multiples
    By coach in forum MySQL Help
    Replies: 5
    Last Post: February 16th, 2004, 08:39 AM
  2. Replies: 8
    Last Post: January 29th, 2004, 11:45 AM
  3. sql query
    By ironchef in forum Database Management
    Replies: 2
    Last Post: January 4th, 2004, 10:44 PM
  4. Forming query with checkboxes
    By buckenmeyer in forum PHP Development
    Replies: 3
    Last Post: December 26th, 2003, 06:21 PM
  5. Replies: 1
    Last Post: December 19th, 2003, 10:12 AM

IMN logo majestic logo threadwatch logo seochat tools logo