Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/253.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
基于配料的PHP和MySQL配方查找器_Php_Mysql - Fatal编程技术网

基于配料的PHP和MySQL配方查找器

基于配料的PHP和MySQL配方查找器,php,mysql,Php,Mysql,我正在开发一个烹饪食谱网站,我想创建一个基于使用增量的食谱查找器 我现在的finder只对3种成分有效 查找器应根据使用的增量返回正确的配方(应使用1-n*) 我的桌子: CREATE TABLE IF NOT EXISTS `INGREDIENTS` ( `ingredients_id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(45) NOT NULL, PRIMARY KEY (`ingredients_id`) ) ENG

我正在开发一个烹饪食谱网站,我想创建一个基于使用增量的食谱查找器

我现在的finder只对3种成分有效

查找器应根据使用的增量返回正确的配方(应使用1-n*)

我的桌子:

CREATE TABLE IF NOT EXISTS `INGREDIENTS` (
  `ingredients_id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(45) NOT NULL,
  PRIMARY KEY (`ingredients_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=17 ;

CREATE TABLE IF NOT EXISTS `INGREDIENTS_POS` (
  `ingredients_pos_id` int(11) NOT NULL AUTO_INCREMENT,
  `ingredients_id` int(11) NOT NULL,
  `ingredients_unit` varchar(20) NOT NULL,
  PRIMARY KEY (`ingredients_pos_id`),
  KEY `ingredients_detail_fk` (`ingredients_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=17 ;

CREATE TABLE IF NOT EXISTS `RECIPES` (
  `recipes_id` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(50) COLLATE utf8_bin NOT NULL,
  `text` varchar(2000) COLLATE utf8_bin NOT NULL,
  `count_persons` int(11) NOT NULL,
  `duration` int(11) NOT NULL,
  `user_id` int(11) NOT NULL,
  `date` datetime NOT NULL,
  `accepted` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`recipes_id`),
  KEY `recipes_user_fk` (`user_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=88 ;

CREATE TABLE IF NOT EXISTS `RECIPES_POS` (
  `recipes_pos_id` int(11) NOT NULL AUTO_INCREMENT,
  `recipes_id` int(11) NOT NULL,
  `ingredients_id` int(11) NOT NULL,
  `ingredients_value` int(11) NOT NULL,
  PRIMARY KEY (`recipes_pos_id`),
  KEY `recipe_pos_rec_id` (`recipes_id`),
  KEY `recipes_pos_ingredient_fk` (`ingredients_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=58 ;
我的错误解决方案(不支持从1-n开始计数):


那个查询对我帮助很大:

   select r.recipes_id
    from RECIPES r
    inner join RECIPES_POS rp on r.recipes_id = rp.recipes_id
    where rp.ingredients_id in (4, 6)
    group by r.recipes_id
    having count(distinct rp.ingredients_id) = 2

请定义“更好”-如果你问一个问题,你可能会在这里得到一些帮助和答案。这里什么是
n
?星星在数学中的用法是什么?你知道
JOIN
SQL子句吗?我认为您可能可以取消第一个查询,而将该表加入。您很容易受到SQL注入的攻击。将
$ing
插入SQL语句时,请在其上使用。或者,使用准备好的语句。超全局$\u GET和$\u REQUEST已经解码。对$\u GET或$\u请求中的元素使用urldecode()可能会产生意外和危险的结果。资料来源:
   select r.recipes_id
    from RECIPES r
    inner join RECIPES_POS rp on r.recipes_id = rp.recipes_id
    where rp.ingredients_id in (4, 6)
    group by r.recipes_id
    having count(distinct rp.ingredients_id) = 2