简体   繁体   English

Mysql和PHP LIKE查询在页面上未生成任何结果,但在Mysql中返回结果

[英]Mysql and PHP LIKE query generates no results on page but returns result in Mysql

Im using a multiple LiKE queries on a table in mysql, The query is being generated from another table and then sent to Mysql. 我在mysql的一个表上使用多个LiKE查询,该查询是从另一个表生成的,然后发送到Mysql。 The actual query when run generates results but when i run it on the page it returns nothing?? 实际查询在运行时会生成结果,但是当我在页面上运行它时,它什么也不返回? Secondly there must be a simpler way to run the same query using less LIKE command maybe 其次,必须有一种更简单的方法来使用更少的LIKE命令来运行相同的查询

mysql_query("SELECT FROM fm_sources WHERE title,excerpt LIKE (list of items to query against)")

this is the code that im using to build the query 这是即时消息用于构建查询的代码

function parse_club_search($club)
{
    $club="'%".$club."%'";
    $club=mysql_query("SELECT * FROM fm_clubs WHERE name LIKE $club");
    while($row=mysql_fetch_assoc($club))
{
    $search_string=$row['search'];
    $search_staff=$row['staff'];
    $search_players=$row['players'];
}

$search_string=explode(",",$search_string);
$search_staff=explode(",",$search_staff);
$search_players=explode(",",$search_players);

$full_string=array_merge($search_staff,$search_players,$search_string);
array_pop($full_string);
$full_string_legnth=count($full_string);

$sql_query_holder="";

$array_track=0;

foreach($full_string as $tag)
{

   if($array_track!=($full_string_legnth-1))
   {
        echo $tag."<br/>";
        $sql_query_holder=$sql_query_holder." excerpt LIKE '%".$tag."%' OR title LIKE '%".$tag."%' OR";
        $array_track++;
    }
    else
    {
        $sql_query_holder=$sql_query_holder." excerpt LIKE '%".$tag."%' OR title LIKE '%".$tag."%'";
        $array_track++;
    }
}

echo $sql_query_holder."<br/><br/>";

$sql_query_holder="\"".$sql_query_holder."\"";
$search=mysql_query("SELECT * FROM fm_sources WHERE $sql_query_holder ORDER BY tweet_count DESC");

and this is the echoed output of the query and then when run no results. 这是查询的回显输出,然后在运行时无结果。

excerpt LIKE '%Roy Hodgson%' OR title LIKE '%Roy Hodgson%' OR excerpt LIKE '%Sammy Lee%' OR title LIKE '%Sammy Lee%' OR excerpt LIKE '%Kenny Dalglish%' OR title LIKE '%Kenny Dalglish%' OR excerpt LIKE '%Brad Jones%' OR title LIKE '%Brad Jones%' OR excerpt LIKE '%Glen Johnson%' OR title LIKE '%Glen Johnson%' OR excerpt LIKE '%Paul Konchesky%' OR title LIKE '%Paul Konchesky%' OR excerpt LIKE '%Raul Meireles%' OR title LIKE '%Raul Meireles%' OR excerpt LIKE '%Daniel Agger%' OR title LIKE '%Daniel Agger%' OR excerpt LIKE '%Fabio Aurelio%' OR title LIKE '%Fabio Aurelio%' OR excerpt LIKE '%Steven Gerrard%' OR title LIKE '%Steven Gerrard%' OR excerpt LIKE '%Fernando Torres%' OR title LIKE '%Fernando Torres%' OR excerpt LIKE '%Joe Cole%' OR title LIKE '%Joe Cole%' OR excerpt LIKE '%Daniel Pacheco%' OR title LIKE '%Daniel Pacheco%' OR excerpt LIKE '%Milan Jovanovic%' OR title LIKE '%Milan Jovanovic%' OR excerpt LIKE '%Sotirios Kyrgiakos%' OR title LIKE '%Sotirios Kyrgiakos%' OR excerpt LIKE '%M 摘录类似'%Roy Hodgson%'或标题类似'%Roy Hodgson%'或摘录类似'%Sammy Lee%'或标题摘录'%Sammy Lee%'或摘录类似'%Kenny Dalglish%'或标题像'%Kenny Dalglish%'或摘录,如'%Brad Jones%'或标题,如LIKE'%Brad Jones%',或摘录,如'%Glen Johnson%',或标题,如'%Glen Johnson%',或摘录,如,'%Paul Konchesky%',或标题像'%Paul Konchesky%'或摘录像'%Raul Meireles%'或标题像'%Raul Meireles%'或摘录像'%Daniel Agger%'或标题像'%Daniel Agger%'或摘录像'%Fabio Aurelio %'或标题类似'%Fabio Aurelio%'或摘录类似'%Steven Gerrard%'或标题类似'%Steven Gerrard%'或摘录类似'%Fernando Torres%'或标题类似'%Fernando Torres%'或摘录类似'%Joe Cole%'或标题类似'%Joe Cole%'或节选类似'%Daniel Pacheco%'或标题类似'%Daniel Pacheco%'或节选类似'%Milan Jovanovic%'或标题类似'%Milan Jovanovic% '或摘录,如'%Sotirios Kyrgiakos%'或标题,如摘录'%Sotirios Kyrgiakos%'或摘录,如'%M axi Rodriguez%' OR title LIKE '%Maxi Rodriguez%' OR excerpt LIKE '%Dirk Kuyt%' OR title LIKE '%Dirk Kuyt%' OR excerpt LIKE '%Ryan Babel%' OR title LIKE '%Ryan Babel%' OR excerpt LIKE '%Lucas%' OR title LIKE '%Lucas%' OR excerpt LIKE '%Danny Wilson%' OR title LIKE '%Danny Wilson%' OR excerpt LIKE '%Jamie Carragher%' OR title LIKE '%Jamie Carragher%' OR excerpt LIKE '%David NGog%' OR title LIKE '%David NGog%' OR excerpt LIKE '%Pepe Reina%' OR title LIKE '%Pepe Reina%' OR excerpt LIKE '%Jay Spearing%' OR title LIKE '%Jay Spearing%' OR excerpt LIKE '%Christian Poulsen%' OR title LIKE '%Christian Poulsen%' OR excerpt LIKE '%Charles Itandje%' OR title LIKE '%Charles Itandje%' OR excerpt LIKE '%Stephen Darby%' OR title LIKE '%Stephen Darby%' OR excerpt LIKE '%Jonjo Shelvey%' OR title LIKE '%Jonjo Shelvey%' OR excerpt LIKE '%Martin Kelly%' OR title LIKE '%Martin Kelly%' OR excerpt LIKE '%Steven Irwin%' OR title LIKE '%Steven Irwin%' OR excerpt LIKE '%Martin Skrtel%' OR title LIKE '%Martin Skrt axi Rodriguez%'或标题类似'%Maxi Rodriguez%'或节选类似'%Dirk Kuyt%'或标题类似'%Dirk Kuyt%'或节选类似'%Ryan Babel%'或标题类似'%Ryan Babel%'OR摘录喜欢'%Lucas%'或标题赞'%Lucas%'或摘录喜欢'%Danny Wilson%'或标题喜欢'%Danny Wilson%'或摘录喜欢'%Jamie Carragher%'或标题喜欢'%Jamie Carragher% '或摘录类似'%David NGog%'或称谓类似'%David NGog%'或摘录类似'%Pepe Reina%'或称谓类似'%Pepe Reina%'或摘录类似'%Jay Spearing%'或称赞类似' %Jay Spearing%'或类似LIKE'%Christian Poulsen%'或标题LIKE'%Christian Poulsen%'或标题LIKE'%Charles Itandje%'或标题LIKE'%Charles Itandje%'或标题LIKE'%Stephen Darby%'或标题类似'%Stephen Darby%'或节选类似'%Jonjo Shelvey%'或标题类似'%Jonjo Shelvey%'或标题类似'%Martin Kelly%'或标题类似'%Martin Kelly%'或标题类似'%史蒂文·欧文%'或头衔喜欢'%史蒂文·欧文%'或摘录象'%Martin Skrtel%'或头衔像'%Martin Skrt el%' OR excerpt LIKE '%Nathan Eccleston%' OR title LIKE '%Nathan Eccleston%' OR excerpt LIKE '%Daniel Ayala%' OR title LIKE '%Daniel Ayala%' OR excerpt LIKE '%Martin Hansen%' OR title LIKE '%Martin Hansen%' OR excerpt LIKE '%Peter Gulacsi%' OR title LIKE '%Peter Gulacsi%' OR excerpt LIKE '%Dean Bouzanis%' OR title LIKE '%Dean Bouzanis%' OR excerpt LIKE '%Victor Palsson%' OR title LIKE '%Victor Palsson%' OR excerpt LIKE '%Tom Ince%' OR title LIKE '%Tom Ince%' OR excerpt LIKE '%David Amoo%' OR title LIKE '%David Amoo%' OR excerpt LIKE '%Andre Wisdom%' OR title LIKE '%Andre Wisdom%' OR excerpt LIKE '%Gerardo Bruna%' OR title LIKE '%Gerardo Bruna%' OR excerpt LIKE '%Jack Robinson%' OR title LIKE '%Jack Robinson%' OR excerpt LIKE '%liverpool%' OR title LIKE '%liverpool%' OR excerpt LIKE '%lfc%' OR title LIKE '%lfc%' el%'或摘录类似'%Nathan Eccleston%'或标题类似'%Nathan Eccleston%'或摘录类似'%Daniel Ayala%'或标题像'%Daniel Ayala%'或摘录类似'%Martin Hansen%'或标题像'%Martin Hansen%'或摘录像'%Peter Gulacsi%'或标题像'%Peter Gulacsi%'或摘录像'%Dean Bouzanis%'或标题像'%Dean Bouzanis%'或摘录像'%Victor Palsson %'或标题类似'%Victor Palsson%'或摘录类似'%Tom Ince%'或标题类似'%Tom Ince%'或摘录类似'%David Amoo%'或标题类似'%David Amoo%'或摘录类似'%Andre Wisdom%'或标题类似'%Andre Wisdom%'或节选类似'%Gerardo Bruna%'或标题类似'%Gerardo Bruna%'或节选类似'%Jack Robinson%'或标题类似'%Jack Robinson% '或摘录类似'%liverpool%'或标题类似'%liverpool%'或摘录类似'%lfc%'或标题类似'%lfc%'

The problem is this line: 问题是这一行:

$sql_query_holder="\"".$sql_query_holder."\"";

Your script doesn't output the whole query, just part of it, which it then modifies. 您的脚本不会输出整个查询,只是一部分查询,然后进行修改。 No wonder you couldn't see what was wrong. 难怪你看不到出什么问题了。

The query it's running is actually: 它正在运行的查询实际上是:

SELECT * FROM fm_sources WHERE "excerpt LIKE '%Roy Hodgson%' OR title LIKE '%Roy Hodgson%' <etc etc> " ORDER BY tweet_count DESC

You don't need those extra inverted commas 您不需要那些多余的逗号

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM