Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8675025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:50:55+00:00 2026-06-12T19:50:55+00:00

Sorry for the fairly ambiguous and long question. I am creating a search form

  • 0

Sorry for the fairly ambiguous and long question.

I am creating a search form for a packaging database and over the past few days I have had a few problems with creating one of the forms that searches for the height of a packet. I want the form to display all results associated with a users input instead of it just returning the exact results. I couldn’t get anything like that working. So I have resorted to creating a dropdown box that searches within a range.

HTML Dropdown:

        <body>
               <label for="trayheight">Height: </label>
                <select name="trayheight">
                    <option value="">All</option>
                    <option value="1">100 - 199 range</option>
                    <option value="2">200 - 299 range</option>
                    <option value="3">300 - 399 range</option>
                </select><br />
        </body>

Here is the dropdown ranges (I also will be adding a range that searches for the 70 – 80 packets). As you can see the option value in each just consists of one number (“1,2,3”), this is so the database will return any results that has (for example) a 1 in it. So if a user searches for something in the “100-199” range, the SQL query will return all the results that are within that range, but currently also return anything with a “1” in it e.g. height “201”. I want to change it so the SQL query will take the value and then use it to compare it to the first number in a record e.g. the 1 in (1)21, so the results that return should only be within that range and nothing else such as “212” won’t return. Is there some form of server code that would deal with this?

Here is my server side code:

       <body>

        <?php
            $con = mysql_connect ("localhost", "root", "");
                   mysql_select_db ("delyn_db", $con);

            if (!$con)
                { 
                    die ("Could not connect: " . mysql_error());
                }

            $descrip = mysql_real_escape_string($_POST['descrip']); 
            $width   = mysql_real_escape_string($_POST['width']);
            $depth   = mysql_real_escape_string($_POST['depth']);

            $varHeight= mysql_real_escape_string($_POST['trayheight']);
            $varRange = mysql_real_escape_string($_POST['trayrange']);
            $varType  = mysql_real_escape_string($_POST['traytype']);
            $varShape = mysql_real_escape_string($_POST['trayshape']);
            $varImage = mysql_real_escape_string($_POST['imagename']);

            $sql = "SELECT * FROM delyn WHERE 
                        description LIKE '%".$descrip."%'  
                    AND trayheight  LIKE '%".$varHeight."%'
                    AND trayrange   LIKE '%".$varRange."%' 
                    AND traytype    LIKE '%".$varType."%' 
                    AND trayshape   LIKE '%".$varShape."%'";


            $r_query = mysql_query($sql);

                while ($row = mysql_fetch_array($r_query))
                    { 
                        echo '<br /> <img src="   '. $row['imagename'] . '" width="180" length="100">';
                        echo '<br /> Tool Code:   '. $row['toolcode'];
                        echo '<br /> Description: '. $row['description']; 
                        echo '<br /> Tray range:  '. $row['trayrange']; 
                        echo '<br /> Tray type:   '. $row['traytype'];
                        echo '<br /> Tray size:   '. $row['traysize']; 
                        echo '<br /> Tray shape:  '. $row['trayshape'] . '<br />' . '<br />';  
                    }

                if (mysql_num_rows($r_query) <= 0){
                    echo 'No results match your search, please try again';
               }


        ?>
      </body>

Thanks guys.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T19:50:57+00:00Added an answer on June 12, 2026 at 7:50 pm

    Just construct the range:

    if (isset($varHeight) && !empty($varHeight)) {
        $low = intval($varHeight."00");
        $high= intval($varHeight."99");
    } else {
       $low = intval("000");
       $high= intval("999");
    }
    

    and change the sql query to search for this range:

    AND trayheight  LIKE '%".$varHeight."%'
    

    to

    "AND trayheight  BETWEEN '".$low."' AND '".$high."'"
    

    Of course proper validation should be placed to ensure that $varHeight is a number (presumably between 1 and 9)

    UPDATED in order to catch the absence of $varHeight filter. This assumes that the total minimum of all possible values for $varHeight is 000 and the total maximum is 999

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im fairly new to c sorry if this is a stupid question! i have
Sorry for the fairly general question but I am looking to find out what
First of all, I'm fairly new to Java, so sorry if this question is
Sorry if this question seems stupid, but it's stumped me for a couple days,
Fairly straightforward question. I have a map that I wish to initialize by calling
My question title isn't clear, sorry. I tried ;) I have a binary string
I'm fairly new to OO programming specifically with Java. I have a question pertaining
Sorry to bother you with this question, but I have a question regarding quota
Sorry for the stupid question but I am fairly new to SQL and I'm
Hey guys, sorry for this probably fairly simple question but I'm starting to get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.