www.webdeveloper.com
Results 1 to 2 of 2

Thread: Combining Radio button, drop down menu and search box

  1. #1
    Join Date
    Feb 2012
    Posts
    19

    Combining Radio button, drop down menu and search box

    Ok…here is the site: http://www.halfwayenterprises.com/search/tyrell.htm
    What am trying to do is this…enable users to search 2 ways, but first they have to choose if they want to search documents whose status are current, obsolete, or both. Then they can search by category and subcategory. Finally they can search current, obsolete, or both by search term in documents title, point of contact or purpose. To my surprise everything works ok…until I try to use the search box with the status of “all” aka “both”. Here is the html part...



    <form name="doublecombo" action="second.php"method="POST">

    <label for="status">Status:</label>

    <label for="current">
    <input class="radio_style" id="current" checked="checked" name="status" type="radio" value="current">
    Current
    </label>

    <label for="obsolete">
    <input class="radio_style" id="obsolete" name="status" type="radio" value="obsolete">
    Obsolete
    </label>

    <label for="both">
    <input class="radio_style" id="both" name="status" type="radio" value="both">
    ALL
    </label>

    <br /><br />

    <select name="category" size="1" onChange="redirect(this.options.selectedIndex)">
    <option value="null">Category</option>
    <option value="asset management">Asset Management</option>
    <option value="budget">Budget/Finance</option>
    <option value="central office">Central Office</option>
    <option value="disposal">Disposal</option>
    </select>





    <select name="subcategory">
    <option value="null">Sub-Category</option>
    <option value="Portfolio">Portfolio</option>
    <option value="Pricing">Pricing</option>
    <option value="Valuation">Valuation</option>

    <option value="Disposal">Disposal</option>





    </select>
    <input name="submitted" type="submit" value="GO">
    <br />


    Seach for: <input type="text" name="find" /> in
    <Select NAME="field">
    <Option id="title" VALUE="title">Title</option>
    <Option id="poc" VALUE="poc">POC</option>
    <Option id="purpose" VALUE="purpose">Purpose</option>

    </Select>

    <input type="hidden" name="searching" value="yes" />





    <input name="submitted" type="submit" value="GO">

    </form>
    </p>

    <script>
    <!--

    /*
    Double Combo Script Credit
    By JavaScript Kit (www.javascriptkit.com)
    Over 200+ free JavaScripts here!
    */

    var groups=document.doublecombo.category.options.length
    var group=new Array(groups)
    for (i=0; i<groups; i++)
    group[i]=new Array()

    group[0][0]=new Option("Sub Category")


    group[1][0]=new Option("Portfolio")
    group[1][1]=new Option("Pricing")
    group[1][2]=new Option("Valuation")

    group[3][0]=new Option("Central Office")
    group[4][0]=new Option("Disposal")

    var temp=document.doublecombo.subcategory

    function redirect(x){
    for (m=temp.options.length-1;m>0;m--)
    temp.options[m]=null
    for (i=0;i<group[x].length;i++){
    temp.options[i]=new Option(group[x][i].text,group[x][i].value)
    }
    temp.options[0].selected=true
    }

    function go(){
    location=temp.options[temp.selectedIndex].value
    }
    //-->
    </script>



    <p align="center"><font face="arial" size="-2">This free script provided by</font><br>
    <font face="arial, helvetica" size="-2"><a href="http://javascriptkit.com">JavaScript
    Kit</a></font></p>'

    and here is the PHP part...
    <?



    mysql_connect("localhost", "name", "pass") or die(mysql_error());
    mysql_select_db("name") or die(mysql_error());

    if(isset($_POST["submitted"])){

    $status = $_POST['status'];


    $category = $_POST['category'];
    $subcategory = $_POST['subcategory'];





    echo '<div class="status_div">';

    if($status=='current'){

    $res = mysql_query("SELECT * FROM material WHERE status='$status' AND category='$category' AND subcategory='$subcategory' ORDER BY `documentid` ASC ");

    while ($row = mysql_fetch_assoc($res)) {

    echo '<div class="current">';

    echo $row ['documentid'].' - '.$row['category'].' - '.$row['title'].' - '.$row['status'];

    echo '</div>';

    echo '<br>';

    }

    } if ($status=='obsolete'){

    $res = mysql_query("SELECT * FROM material WHERE status='$status' AND category='$category' ORDER BY `documentid` ASC ");

    while ($row = mysql_fetch_assoc($res)) {

    echo '<div class="obsolete">';

    echo $row ['documentid'].' - '.$row['category'].' - '.$row['title'].' - '.$row['status'];

    echo '</div>';

    echo '<br>';

    }




    } if ($status=='both'){

    $res = mysql_query("SELECT * FROM material WHERE status1='both' AND category='$category' ORDER BY `documentid` ASC");

    while ($row = mysql_fetch_assoc($res)) {

    echo '<div class="">';

    echo $row ['documentid'].' - '.$row['category'].' - '.$row['title'].' - '.$row['status'];

    echo '</div>';

    echo '<br>';

    }

    }








    echo '</div>';

    }




    $field = @$_POST['field'] ;
    $find = @$_POST['find'] ;
    $searching = @$_POST['searching'] ;
    $status = $_POST['status'];

    //This is only displayed if they have submitted the form
    if ($searching =="yes")
    {
    echo "<h2>Results</h2><p>";

    //If they did not enter a search term we give them an error
    if ($find == "")
    {
    echo "<p>You forgot to enter a search term";
    exit;
    }


    // We preform a bit of filtering
    $find = strtoupper($find);
    $find = strip_tags($find);
    $find = trim ($find);

    //Now we search for our search term, in the field the user specified


    $data = mysql_query("SELECT * FROM material WHERE status1='both' AND lower($field) LIKE'%$find%' LIMIT 0,30");

    //And we display the results
    while($row = mysql_fetch_array( $data ))
    {
    echo $row ['documentid'].' - '.$row['category'].' - '.$row['title'].' - '.$row['status'];


    echo "<br>";
    echo "<br>";
    }

    //This counts the number or results - and if there wasn't any it gives them a little message explaining that
    $anymatches=mysql_num_rows($data);
    if ($anymatches == 0)
    {
    echo "Sorry, but we can not find an entry to match your query<br><br>";
    }

    //And we remind them what they searched for
    echo "<b>Searched For:</b> " .$find;
    }
    ?>
    <a href="tyrell.htm"> Return</a>



    Any suggestions? I am stumped and overwhelmed...lol

  2. #2
    Join Date
    Feb 2012
    Location
    Tallahassee, FL
    Posts
    280
    Is this correct:
    Code:
    "SELECT * FROM material WHERE status1='both' AND category='$category' ORDER BY `documentid` ASC"
    Because all the others have "status=" but this one has "status1="...?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles