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

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

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法