ComboBox to choose search field (problem in if statement)

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Dieneces
Forum Newbie
Posts: 4
Joined: Thu Oct 16, 2008 11:16 am

ComboBox to choose search field (problem in if statement)

Post by Dieneces »

Hi guys,

I have a little problem... I created a combo box with two option in a form(search.php):


this is just part of the page code:

Code: Select all

 
    <form action="results.php" name="search" method="post">
      Choose Search Type:<br />
      <select name="searchtype">
        <option value="Name">player</option>
        <option value="Class">Class</option>
    </select>
    <br />
    Enter Search Term:<br />
    <input name="searchterm" type="text">
    <br />
    <input type="submit" name="search" value="Search">
    </form>
 

Now, in the page results.php, that is called and the user chooses to search in the form search.php I want to search by Player ou by class (the 2 combobox options).

So I have two different querys (both work correctly), but the problem is the if...else statement... I tried many things but I thing it should be something like this:

Code: Select all

 
IF (!$searchtype = 'Class') 
    {
    $query = "SELECT * FROM player JOIN classes ON player.Classe = classes.ClasseID WHERE classes.Nome LIKE '%".$searchterm."%'";
    $result = $db->query($query);
    bla bla bla...
    }
else 
    {   
    $query = "select player.Nome,player.Classe,player.EXP from player where ".$searchtype." like '%".$searchterm."%'";
    $result = $db->query($query);
    bla bla bla...
    };
 
I now this isn't it... But I can't find a way to retrieve the option in the combobox.... please anyone can point me in the right direction?

Many thanks in advance
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: ComboBox to choose search field (problem in if statement)

Post by papa »

IF (!$searchtype == 'Class')
Dieneces
Forum Newbie
Posts: 4
Joined: Thu Oct 16, 2008 11:16 am

Re: ComboBox to choose search field (problem in if statement)

Post by Dieneces »

omg.... Now I feel ashamed.... worst than simple... lol


thanks for the quick reply ;)
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: ComboBox to choose search field (problem in if statement)

Post by papa »

np :drunk:
Post Reply