Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Feb 2010
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Search form help

    Hi there I asked about this in another forum however did not receive much helpful response on this.

    I have a search form, that is to search for members across my site. see below:

    PHP Code:
    <form method="post" action="quick-search.php">
                    
                        <
    div class="form_row">
                            <
    label>Instrument group played</label>
                            <
    select name="instrument">
                                <
    option></option>
                                <
    option value "strings">Strings</option>
                                <
    option value "percussion">Percussion</option>
                                <
    option value "brass">Brass</option>
                                <
    option value "DJ">DJ</option>
                                <
    option value "wind">Wind</option>
                                <
    option value "vocals">Vocals</option>
                            </
    select><br />
                            
                            <
    label>Looking for</label>
                            <
    select name="seeking">
                                <
    option></option>
                                <
    option>musician</option>
                                <
    option>Band</option
                                <
    option>Venue</option>                                                       
                            </
    select>
                        </
    div>
                        
                        <
    div class="form_row">
                            <
    label>Looking to</label>
                            <
    select name="purpose">
                                <
    option></option>
                                <
    option value="Form a band">Form a band </option>
                                  <
    option value="Jam">Jam </option>
                                  <
    option value="Perform">Perform </option>
                                  <
    option value="One off performance">One off performance </option>
                                  <
    option value="Regular performance">Regular Performance </option>
                            </
    select>
                        </
    div>
                        
                        <
    div class="form_row">
                            <
    label>Age looking for</label>
                            <
    select name="age">
                                <
    option></option>
                                <
    option value="13">13 </option>
                                <
    option value="14">14 </option>
                                <
    option value="15">15 </option>
                                <
    option value="16">16 </option>
                                <
    option value="17">17 </option>
                                <
    option value="18">18 </option>
                                <
    option value="19">19 </option>
                                <
    option value="20">20 </option>
                                <
    option value="21">21 </option>
                                <
    option value="22">22 </option>
                                <
    option value="23">23 </option>
                                <
    option value="24">24 </option>
                                <
    option value="25">26 </option>
                                <
    option value="27">27 </option>
                                <
    option value="28">28 </option>
                                <
    option value="29">29 </option>
                                <
    option value="30">30 </option>
                                <
    option value="31">31 </option>
                                <
    option value="32">32 </option>
                                <
    option value="33">33 </option>
                                <
    option value="34">34 </option>
                                <
    option value="35">35 </option>
                                <
    option value="36">36 </option>
                                <
    option value="37">37 </option>
                                <
    option value="38">38 </option>
                                <
    option value="39">39 </option>
                                <
    option value="41">40 </option>
                                <
    option value="42">42 </option>
                                <
    option value="43">43 </option>
                                <
    option value="44">44 </option>
                                <
    option value="45">45 </option>
                          </
    select>
                             
                        </
    div>
                        <
    div class="form_row">
                            <
    label>By Postcode</label>
                            <
    input class="inputfield" name="pc" type="text" />
                        </
    div>
                        
                        <
    div class="form_row">
                            <
    label>By Location</label>
                            <
    select name="location">
                            <
    option></option>
                          <
    option value "Aberdeenshire">Aberdeenshire</option>
                          <
    option value "Angus">Angus</option>
                          <
    option value "Argyll and Bute">Argyll and Bute</option>
                          <
    option value "Ayrshire">Ayrshire</option>
                          <
    option value "Bedfordshire">Bedfordshire</option>
                          <
    option value "Berkshire">Berkshire</option>
                          <
    option value "Wrexham">Wrexham</option>
                          <
    option value "Buckinghamshire">Buckinghamshire</option>
                          <
    option value "Cambridgeshire">Cambridgeshire</option>
                          <
    option value "Cheshire">Cheshire</option>
                          <
    option value "Clackmannanshire">Clackmannanshire</option>
                         <
    option value "Cornwall">Cornwall</option>
                          <
    option value "Derbyshire">Derbyshire</option>
                          <
    option value "Devon">Devon</option>
                         <
    option value "Dorset">Dorset</option>
                          <
    option value "Dunbartonshire">Dunbartonshire</option>
                          <
    option value "Durham">Durham</option>
                          <
    option value "East Lothian">East Lothian</option>
                         <
    option value "Essex">Essex</option>
                          <
    option value "Fife">Fife</option>
                

                          </
    select>   
                      </
    div>
                        
                        <
    div class="form_row">
                            <
    label>By name of member/band</label>
                          <
    input class="inputfield" name="name" type="text" />
                        </
    div>
                        
                        
                        <
    input type="submit" value="Submit" id="Submit" />
                        
                    </
    form
    Sorry for the long code, but It will make it clearer as to what I want. As seen from the form I have several inputs to search for, however I am not sure how to do the sql statement so that it either searches for one or a few of the search fields.

    I was given this code to help me.

    PHP Code:
    $count=1;
    $qry "SELECT * FROM profiles"
    if($instrument != '') {$qry .= ($count==1" WHERE"" AND") . "instrument = '" $instrument "' ";$count++;}
    if(
    $purpose != '') {$qry .= ($count==1" WHERE"" AND") . "purpose = '" $purpose "'"$count++;}
    if(
    $seeking != '') {$qry .= ($count==1" WHERE"" AND") . "seeking= '" $seeking "'";$count++;}
    if(
    $age != '') {$qry .= ($count==1" WHERE"" AND") . "age = '" $age "'";$count++;} 
    I was told that this code would allow the search to either only take one field or several to return a specific result so for example 'age-20 who plays guitar'.
    This example uses wildcard, however my search form has mainly drop down menus, so how can this format be put here?

    Also if I try to run this, it errors saying 'unexpected T_IF line 110'....110 being the first IF in this..


    Any help would be greatly appreciated.!

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    missing asemi-colon at the end of this line

    $qry = "SELECT * FROM profiles"

  • #3
    New Coder
    Join Date
    Feb 2010
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok thanks, that fixed the error.

    But could someone help me with the code? It just returns every single member, regardless of what is searched.

  • #4
    New Coder
    Join Date
    Feb 2010
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    $count=1
    $result "SELECT * FROM profiles";
    if(
    $instrument != '') {$result .= ($count==1" WHERE"" AND") . "instrument = $instrument ";$count++;} 
    if(
    $purpose != '') {$result .= ($count==1" WHERE"" AND") . "purpose =$purpose"$count++;} 
    if(
    $seeking != '') {$result .= ($count==1" WHERE"" AND") . "seeking= '$seeking";$count++;} 
    if(
    $age != '') {$result .= ($count==1" WHERE"" AND") . "age = $age ";$count++;}  


    $numresults=mysql_query($result);

    $num_results mysql_num_rows($numresults); 
    I'm getting an error on the &num_results

    "Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\Users\Ash\Documents\Testing site\xampp\htdocs\upload\quick-search.php on line 118"

    I'm not sure why, anyone help?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •