Mysqli子查询与重复变量和在中 [英] Mysqli subquery with repeated variable and in with like

查看:80
本文介绍了Mysqli子查询与重复变量和在中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个子查询,搜索所有具有特定书籍的类型,并且查询使其查找具有子查询类型的所有书籍,并创建重复相同书籍和创建的时间计数一个新的柜台专栏。剩余的有序查询基于重复次数较多的书籍。



此查询有效,但问题出现在我尝试使用mysqli在服务器部分插入变量时。我正在尝试为面向对象执行此操作,但它不会返回结果。



 //我使用了字母,因为你可以更好地理解

$ book = $ get_id_book;
$ book =%$ book%;

$ result = $ link-> prepare(SELECT b.name,COUNT(name)AS duplicatelicated,c.arxive,t.type,t.name_type
FROM Books b,涵盖c,类型t,Genres_book g
WHERE b.id_book = c.id_cover_book AND
b.id_book = g.id_genre_book AND
g.id_book_genre IN(SELECT id_book_genre
FROM Book b1,Genres_book g1
WHERE b1.id_book = g1.id_genre_book AND
b1.id_book IN(?))AND
NOT(b.id_book =?)
GROUP BY b。 name
ORDER BY重复的DESC);

$ result-> bind_param('i',$ book);

if($ result-> execute()){
$ result-> bind_result($ name,$ duplicated,$ arxive,$ type,$ name_type);
while($ result-> fetch()){
echo....;
}
}





我的尝试:



嗯,我正在寻找所有帖子,但没有任何效果。我尝试了REGEXP和类似但返回不正确的结果。



On

 b1.id_book IN(?)

我想要这样的东西:

 b1.id_book IN喜欢?



对不起我的英语,我很绝望我希望有人可以帮助我。

解决方案

book =


get_id_book;


book =%

I have a subquery that search all the genres that have an specific book, and the query makes it find all the books that have those genres of the subquery and it is creates a count of the times that repeat the same books and creates a new column of the counter. The orderly query remaining is based on books that are repeated more to less.

This query works but the problem comes when i tried to insert variable at server part with mysqli. I'm trying to do it for oriented objects but it does not return results.

//I used asigned letters because you can understand better

$book = $get_id_book;                
$book = "%$book%";

$result = $link->prepare ("SELECT b.name, COUNT(name) AS duplicated, c.arxive, t.type, t.name_type
FROM Books b, Covers c, Types t, Genres_book g
WHERE b.id_book = c.id_cover_book AND
b.id_book = g.id_genre_book AND
g.id_book_genre IN ( SELECT id_book_genre
                      FROM Book b1, Genres_book g1
                      WHERE b1.id_book = g1.id_genre_book AND
                      b1.id_book IN (?)) AND
 NOT (b.id_book = ?)
 GROUP BY b.name
 ORDER BY duplicated DESC");

$result->bind_param('i', $book);

if($result->execute()){
   $result->bind_result($name, $duplicated, $arxive, $type, $name_type);
   while ($result->fetch()) {
    echo "....";
   }
}



What I have tried:

Well, i was looking for all post but nothing has worked. I tried REGEXP and similars but returns results that aren't correct.

On

b1.id_book IN (?)

I want something like this:

b1.id_book IN like ?


Sorry for my english, I'm desperate I hope someone can help me out.

解决方案

book =


get_id_book;


book = "%


这篇关于Mysqli子查询与重复变量和在中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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