1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Rep Power

    Search using drop down list

    hello guys,

    i need some help regarding search by on my website. here is my point, i have a field and a drop down. i choose, lets say product name in the drop down and insert the name to search. this works great. even the picture is displayed. i want to add brand to the drop down list so that i have 2 options. how do i do the search when the brand option is selected in the drop down. i need a tutorial regarding that? mysql table to be queried....
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Rep Power

    how about you write the code yourself rather than copying and pasting it from some tutorial?

    Since the general search logic seems to work already, it shouldn't be too hard to add an if statement to the PHP code, which distinguishes between the different options and changes the query accordingly.

    If you want concrete advice, we need to see your current code (not all of it, just the relevant parts).
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Rep Power
    i have this code below but am having errors when running it. when i select the brand in the drop down i get errors at the line mysql_fetch_array and mysql_num_rows


    echo "<h2>Search Results:</h2><p>";

    $find = $_POST['find'];

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

    // Otherwise we connect to our Database

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

    if ($find=='Name'){
    //Now we search for our search term, in the field the user specified
    $data = mysql_query("SELECT * FROM tbl_product WHERE prod_name LIKE'%$find%'");

    elseif ($find=='Brand'){

    $data = mysql_query("SELECT * FROM tbl_product WHERE prod_brand LIKE'%$find%'");

    print "
    <table border=\"5\" cellpadding=\"5\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#808080\" width=\"100&#37;\" id=\"AutoNumber2\" bgcolor=\"#C0C0C0\"><tr>
    <td width=100>Product</td>
    <td width=100>Name:</td>
    <td width=100>Brand:</td>
    <td width=100>Product Details:</td>
    <td width=100>Price:</td>
    <td width=100>Weight:</td>

    //And we display the results
    while($result = mysql_fetch_array( $data ))

    print "<tr>";
    print '<td><img src="Images/Products/'.$result['prod_photo'].'"/></td>';
    print "<td>" . $result['prod_name'] . "</td>";
    print "<td>" . $result['prod_brand'] ."</td>";
    print "<td>" . $result['prod_desc'] . "</td>";
    print "<td>" . $result['prod_price'] . "</td>";
    print "<td>" . $result['prod_w_c'] . "</td>";
    print "</tr>";
    print "</table>";

    //This counts the number or results - and if there wasn't any it gives them a little message explaining that
    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;

IMN logo majestic logo threadwatch logo seochat tools logo