只想按成分搜索我的数据库 [英] Wanting to search my database by ingredients only

查看:74
本文介绍了只想按成分搜索我的数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好,在我的网站上,我希望人们可以输入他们拥有的3种食材并搜索我的数据库.现在,它调出了数据库中所有的配方,所以我想知道如何才能将其缩小到配方.我的网站上有一个搜索栏,可让您按类别,名称,成分进行搜索,并且效果很好,因此,我并不认为这样做会很困难,因为我只希望它能够搜索成分,但这给了我所有的食谱,这里是我使用的代码,类似于我的搜索栏,减去类别和名称.

Ok on my site i want to be able to have people enter 3 ingredients they have and have it search my database. Right now it brings up all recipes i have in the database, so what I am wondering is how can i get it to narrow it down to recipes. I have a search bar on my site that will let you search by category, name, ingredient and it works perfect, so I didn''t think that this would be that hard to do since I just want it to be able to search an ingredient, but it is giving me all recipes here is the code I use which is similar to my search bar minus the category and name.

<<pre lang="xml">?php
echo $_POST[''term''];
?>
<?php
require_once("database.php");

$term = $_POST[''term''];
$sql = mysql_query("SELECT * FROM `Recipe` WHERE `ingredients` like ''%$term%'' or `ingredients` like ''%$term%'' or `ingredients` like ''%$term%''") or die(mysql_error());
while ($row = mysql_fetch_array($sql))
{
    echo ''<br/>'';
    echo ''<br/>'';
    echo ''Category: ''.$row[''category''];
    echo ''<br/>'';
    echo ''<br/> Recipe Name: ''.$row[''recipename''];
    echo ''<br/>'';
    echo ''<br/> Ingredients: ''.$row[''ingredients''];
    echo ''<br/>'';
    echo ''<br/> Preparations: ''.$row[''preparations''];
    echo ''<br/>'';
    echo ''<br/> Cooking Time: ''.$row[''cookingtime''];
    echo ''<br/>'';
    echo ''<br/> Servings: ''.$row[''servings''];
    echo ''<br/>'';
    echo ''<br/> Optional Notes: ''.$row[''optionalnotes''];
    echo ''<br/><br/>'';
}
?>
<form action="<?php echo $_SERVER[''PHP_SELF'']; ?>" method="post">
 <table border="0">
 <h1> Meal Finder</h1>
<h2>Enter 3 ingredients</h2>
 <tr><td>I have:</td><td>
 <input type="text" name="ingredients" maxlength="40">
 </td></tr>
 <tr><td>and:</td><td>
 <input type="text" name="ingredients" maxlength="50"></td></tr>
  <tr><td>and:</td><td>
 <input type="text" name="ingredients" maxlength="50">
 </td></tr>

 <tr> <td align="left">
 </td></tr>
 </table>
 <input type="submit" name="submit" value="Submit" />
 </form>


</body>
</html


>


>

推荐答案

_POST [''term'']; ?> <?php require_once("database.php");
_POST[''term'']; ?> <?php require_once("database.php");


term =


_POST [''term''];
_POST[''term''];


这篇关于只想按成分搜索我的数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆