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

  • SEARCH
  • Home
  • 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 8666759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:48:34+00:00 2026-06-12T17:48:34+00:00

I am creating a multi-form search box that searches a Meat packaging database. The

  • 0

I am creating a multi-form search box that searches a Meat packaging database. The search works only if users are specific, I want them to be able to search the database without having to choose a specific option. Three of the form boxes are for users to search width, height and depth all numerical values, but they only return results if the user is exact with the sizes. I want the search to be able to return the nearest value if it cannot find an exact match to the one entered by the user.

Such as:

If user enters “252” in the width box, it will currently return “No searches found”
But there is a “251” in the database. So if the user types in “252” the SQL query then automatically looks for the nearest sizes and then displays in theory “251”.

Here is the HTML and PHP:

<body>

    <form action="form3.php" method="post"> 
      <label for ="description">Description:</label>
      <input type="text" name="descrip" /><br />

      <label for ="trayheight">Trayheight:</label>
      <input type="text" name="height" /> <br /> 

      <label for ="traywidth">Traywidth:</label>
      <input type="text" name="width" /> <br />

      <label for ="traydepth">Traydepth:</label>
      <input type="text" name="depth" /> <br />

      <label for="trayrange">Trayrange: </label>
                <select name="trayrange">
                    <option value=""></option>

                    <option value="BBQ">BBQ</option>

                    <option value="Dessert">Dessert</option>

                    <option value="Display">Display</option>

                    <option value="Meat">Meat</option>   

                    <option value="Microwave">Microwave</option>

                    <option value="Party">Party</option>

                    <option value="Salad/Wet Pasta">Salad/Wet Pasta</option>

                    <option value="Snacks">Snacks</option>

                    <option value="Standard">Standard</option>

                </select>

        <label for ="traytype">Traytype: </label> 
            <select name="traytype">
                    <option value=""></option>

                <option value="Open">Open</option>

            <option value="Cavitised">Cavitised</option>

                    <option value="Lid">Lid</option>

                    <option value="Tray">Tray</option>

                    <option value="Coallition">Coallition</option>

                    <option value="Bowl">Bowl</option>

                    <option value="Hinge pack">Open</option>

                    <option value="Pot">Pot</option>

                    <option value="Base & Lid">Base and Lid</option>

                    <option value="Rectangular">Rectangular</option>

                    <option value="Specalist">Specialist</option>
            </select><br />

        <label for="trayshape">Trayshape: </label>
            <select name="trayshape">
                    <option value=""></option>

            <option value="Rectangular">Rectangular</option>

                <option value="Oval">Oval</option>

                <option value="Square">Square</option>

                    <option value="Insert">Insert</option>

                    <option value="Round">Round</option>

                    <option value="Open">Open</option>
            </select><br />

        <input type="submit" value="Submit" /> 
    </form> 

    </body>

And the PHP:

   <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']); 
            $height  = mysql_real_escape_string($_POST['height']);
            $width   = mysql_real_escape_string($_POST['width']);
            $depth   = mysql_real_escape_string($_POST['depth']);

            $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 '%".$height."%' 
                    AND traywidth LIKE '%".$width."%' 
                    AND traydepth LIKE '%".$depth."%' 
                    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 /> 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'];  
                    echo '<br /> <img src="   '. $row['imagename'] . '"
                                    width="200" length="100">' . '<br />' . '<br />';  
                    }

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

If anyone could help that would be great, thanks in advance 🙂

EDIT:

   <body>
        $scope = 20;
                $width_min = $width - $scope;
                $width_max = $width + $scope;
                $depth_min = $depth - $scope;
                $depth_max = $depth + $scope;
                $height_min = $height - $scope;
                $height_max = $height + $scope;

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

                if ($row = 0) {
            $sql = "SELECT * FROM delyn WHERE 
                        description LIKE '%".$descrip."%' 
                    AND (traywidth BETWEEN ".$width_min." AND ".$width_max.")  
                    AND (traydepth BETWEEN ".$depth_min." AND ".$depth_max.")  
                    AND (trayheight BETWEEN ".$height_min." AND ".$height_max.")  
                    AND trayrange LIKE '%".$varRange."%' 
                    AND traytype LIKE '%".$varType."%' 
                    AND trayshape LIKE '%".$varShape."%'";
                }
    <body>
  • 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-12T17:48:36+00:00Added an answer on June 12, 2026 at 5:48 pm

    Instead of going with a fixed “upper” and “lower” margin, you can sort a list of your entries based upon an absolute calculation between the traywidth in your table and the inputted width by the user. Something like this:

    select d.*, abs(d.traywidth - USER_SEARCH_INPUTTED_WIDTH) as WIDTH_ABS from delyn d order by WIDTH_ABS limit 20;
    

    This will give you a list of nearby traywidths based upon the “USER_SEARCH_INPUTTED_WIDTH”, for instance 252 as relative “distances” from what the user is after and what entries the database actually has.

    Note: all columns you’re allowing search in/for needs to be signed otherwise you’ll end up with funky results (due to abs).

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

Sidebar

Related Questions

I am creating a multi-form search box that searches a Meat packaging database. The
I'm creating a multi-part form in the style that Ryan Bates describes here: http://railscasts.com/episodes/217-multistep-forms
I'm in process creating a form in Plone/PloneFormGen. This form has Multi-Select field that
I'm creating a multi-part web form in ASP.NET that uses Panels for the different
I am creating a Multi project Template The problem is that when I run
I'm creating a form in ASP.NET that would generate a report. And I'm using
I have a form with a multi-select input field that returns an array depending
im creating a multi-modal journey planner application that finds all possible routes a user
I want to make a splash screen without creating multi-threading on the application does
I'm creating a setup wizard using AJAX. It's a multi-step form submission with 6

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.