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

    Join Date
    Jan 2000
    Location
    Belgium
    Posts
    7
    Rep Power
    0
    Hi!

    It's me again. Ok what is the question about.. I'm working on a party-registration site and
    people have the opportunity to search on what they need. For the moment it just searches on the
    type of party and where the party is. The problem is, it shows all the parties of that kind. Now
    I'd like to add a date search too in combination with the other fields. I'm sure I can do this,
    but it seems kinda long to me. There must be a more efficient code I think, anyone out there to
    take a look at this? thnx

    -- search.php3

    <?php
    <?php
    if (( $gemeente == "" ) and ( $soort == "") and ($date == ""))
    {
    $query = "SELECT * FROM $pTABLE LIKE datum = "% $maand %" -WHERE datum >= "$vandaag"";
    echo "Het is u blijkbaar om het even waar het fuifje is.<p>";
    }
    elseif (( $gemeente == "") and ($soort != "") and ($date == ""))
    {
    $query = "SELECT * FROM $pTABLE LIKE datum = "% $maand %" WHERE soort="$soort" AND datum >= "$vandaag" ";
    echo "U bent selectief, bent u echt een $stripped freak?<p>";
    }
    elseif (( $gemeente != "") and ($soort == "") and ($date == ""))
    {
    $query = "SELECT * FROM $pTABLE LIKE datum = "% $maand %" WHERE gemeente="$gemeente" AND datum >= "$vandaag" ";
    echo "Is het dan zo fun in $gemeente?<p>";
    }
    elseif (( $gemeente != "") and ($soort != "") and ($date == ""))
    {
    $query = "SELECT * FROM $pTABLE LIKE datum = "% $maand %" WHERE soort="$soort" AND gemeente="$gemeente" AND datum >= "$vandaag" ";
    echo "Criteria: $stripped in $gemeente <p>";
    }

    ....

    and so on and on..

    9 if-clauses is not such good code i think?

    -Jonathan
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 1999
    Location
    Seattle
    Posts
    133
    Rep Power
    16
    I'm sure that PHP is pretty efficient, but if you're concerned about something easier to read and modify (for adding more choices) you could do something like:

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    $query = "SELECT * FROM $pTABLE LIKE datum = "% $maand %" WHERE " .
    $gemeente != "" ? "gemeente="$gemeente" AND " : "" .
    $sort != "" ? "soort="$soort" AND " : "" .
    $date != "" ? "date="$date" AND " : "" .
    "datum >= "$vandaag"";
    [/code]

    But then you'll lose your echo statements.

    Don
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Posts
    16
    Rep Power
    0
    I might not be understanding the question,
    but I think I would do it like:


    $searchstring="Select * from $table";

    for(a=0;a<count($searchfields[]);a++){
    if ($searchfields[a]!=""{
    $searchstring." where field =".$searchfields[a];
    }
    }
    $query=$searchstring;

    or something roughly like that.

    You could do it a little better with the 'key' array function to extract the field name aswell.

Similar Threads

  1. Frames hijacked after remote search
    By Telejoke in forum Antivirus Protection
    Replies: 2
    Last Post: September 26th, 2007, 09:32 AM
  2. Is there any alternative to fulltext search?
    By irishairpics in forum MySQL Help
    Replies: 2
    Last Post: December 10th, 2003, 02:40 PM
  3. Site html search with php?
    By stojan in forum PHP Development
    Replies: 1
    Last Post: November 17th, 2003, 09:20 PM
  4. Replies: 37
    Last Post: October 2nd, 2003, 08:09 AM
  5. Replies: 2
    Last Post: August 27th, 2003, 02:07 AM

IMN logo majestic logo threadwatch logo seochat tools logo