douzhonglong3789 2012-10-09 07:20
浏览 56
已采纳

可以搜索SQL数据库的HTML下拉表单的“任意”选项?

I am creating a search form that uses multiple forms to get matching results from a database that contains meat packaging information. I want eventually for users to be able to use forms to search for the width, length, type, shape and description of a package. With only the matching results to be displayed.

Currently I have 3 dropdown boxes and all work and find matching results. Unfortunately they seem to completely override the other form terms (another problem), but I want to add in a "Any" function so users can search for anything without having to give a specific search for all the dropdown boxes everytime limiting the amount of results that will appear.

HTML code:

    <body>


    <form action="form3.php" method="post"> 
    <label for ="toolcode">Toolcode: </label> 
    <input type="text" name="term" /><br />
    <label for ="delyncode">Delyn code: </label>
    <input type="text" name="term" /><br />
    <label for ="description">Description: </label>
    <input type="text" name="term" /><br />
    <label for ="traysize">Traysize: </label>
    <input type="text" name="term" /> <br />
    <label for ="trayheight">Trayheight: </label>
    <input type="text" name="term" /> <br /> 
    <label for ="traywidth">Traywidth: </label>
    <input type="text" name="term" /> <br />
    <label for ="traydepth">Traydepth: </label>
    <input type="text" name="term" /> <br />

         <label for="trayrange">Trayrange: </label>
                <select name="trayrange">
                    <option value="Other">--Any--</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="Other">--Any--</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="Other">--Any--</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>

The current "Any" option i have above was just a test. It doesn't work, no results get displayed.

PHP code:

       <body>

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

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

            $varRange = $_POST['trayrange'];
            $varType = $_POST['traytype'];
            $varShape = $_POST['trayshape'];
            $term = mysql_real_escape_string($_POST['term']);    

    $sql = "SELECT * FROM delyn WHERE toolcode LIKE '%".$term."%' AND delyncode LIKE
                   '%".$term."%' AND description LIKE '%".$term."%' AND traysize LIKE
                   '%".$term."%' AND trayheight LIKE '%".$term."%' AND traywidth LIKE
                   '%".$term."%' AND traydepth LIKE '%".$term."%' 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 /> Delyn code:  ' .$row['delyncode']; 
           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 height: '.$row['trayheight']; 
           echo '<br /> Tray width:  '.$row['traywidth']; 
           echo '<br /> Tray depth:  '.$row['traydepth'];
           echo '<br /> Tray shape:  '.$row['trayshape'] . '<br />' . '<br />'; ;  
                    }


        ?>
            </body>

What would I need to add to allow the users to search allowing for any "tray range", "trayshape" and "traytype". This in theory should display results that match the forms that have info entered.

Thanks in advance for anyone who can help.

  • 写回答

1条回答 默认 最新

  • duanao3204 2012-10-09 07:36
    关注

    use different names for different text-fields otherwise they will be overwritten i.e the last text got preferred at server side you will get tray width only because its the last one with name term

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?