Jump to content

how do i search for a AND b not a OR b


nearenough

Recommended Posts

i am very dim and i have this code:

 

$Track = $_GET['Track'];

 

      $RaceDate = $_GET['RaceDate'];

 

  }

{

      $searchSQL = "SELECT RaceDate, RaceNumber, RaceName, RaceDist, Track, Placing, Sorter, Horseid, Trail, Draw, Driver, Dist, Time, Comment FROM RaceTable WHERE ";

   

      // grab the search types.

      $types = array();

      $types[] = $_GET['RaceNumber']?"`RaceNumber` LIKE '$RaceNumber'":'';

      $types[] = $_GET['Track']?"`Track` LIKE '$Track'":'';

 

     

      $types = array_filter($types, "removeEmpty"); // removes any item that was empty (not checked)

 

      if (count($types) < 1)

        $types[] = "`RaceNumber` LIKE '%{$searchTermDB}%'"; // use the body as a default search if none are checked

      $types[] = "`Driver` LIKE '%{$searchTermDB}%'";

      $types[] = "`Track` LIKE '%{$searchTermDB}%'";

 

  $andOr = isset($_GET['matchall'])?'AND':'OR';

  $searchSQL .= implode(" {$andOr} ", $types) . " ORDER BY racedate, racenumber, Sorter, Placing ASC"; // order by title.

 

 

it returns results from that track OR that date, and i need to change it to that track AND that date, which bit do i change please?

 

thank you

Link to comment
Share on other sites

i had a go at writing that and came up with:

 

      $Track = $_GET['Track'];

 

      $RaceDate = $_GET['RaceDate'];

 

 

{

      $searchSQL = "SELECT DISTINCT RaceDate.a_id

      FROM RaceTable WHERE AS RaceDate,RaceTable AS

      Track RaceDate.a_id=Track.a_id AND Racedate.b_id=$RaceDate

      AND instance.b_id=$Track";

   

      // grab the search types.

      $types = array();

      $types[] = $_GET['RaceNumber']?"`RaceNumber` LIKE '$RaceNumber'":'';

      $types[] = $_GET['Track']?"`Track` LIKE '$Track'":'';

 

     

      $types = array_filter($types, "removeEmpty"); // removes any item that was empty (not checked)

 

      if (count($types) < 1)

        $types[] = "`RaceNumber` LIKE '%{$searchTermDB}%'"; // use the body as a default search if none are checked

      $types[] = "`Driver` LIKE '%{$searchTermDB}%'";

      $types[] = "`Track` LIKE '%{$searchTermDB}%'";

 

  $andOr = isset($_GET['matchall'])?'AND':'OR';

  $searchSQL .= implode(" {$andOr} ", $types) . " ORDER BY racedate, racenumber, Sorter, Placing ASC";

 

 

 

 

which dont work....any clues???

 

 

Link to comment
Share on other sites

you should read that article again and try to understand it. it's actually pretty well written.

a_id obviously needs to be your primary key.

 

SELECT DISTINCT instance1.a_id
FROM RaceTable AS instance1,RaceTable AS instance2
WHERE instance1.a_id=instance2.a_id AND instance1.RaceNumber=[something]  AND instance2.Driver=[something]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.