1024programmer PHP Mysql queries whether the first ten rows of data sorted in reverse order contain a certain key word, please help solve it by PHP experts, thank you

Mysql queries whether the first ten rows of data sorted in reverse order contain a certain key word, please help solve it by PHP experts, thank you

select * from member where data!=” order by time desc Limit 0,10

The data in the first ten lines are arranged in reverse order above, how can we further compare the number of key words in these ten lines of data?

That is: data like ‘%$keyword%’ How many of the above 10 items contain the keyword?

17 solutions

#1


select *

from (

select * from member where data!=” order by time desc Limit 0,10

)T

where data like ‘%$keyword%’

#2


select * from

(select * from member where data!=”order by time desc limit 0,10

)a

where data like’%$keyword%’

#3


Reply quoted from floor 1:

select *

from (

select * from member where data!=” order by time desc Limit 0,10

)T

where data like ‘%$keyword%’

I tested it, and got an error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in

Please help me

#4


Quoting the reply from the 2nd floor:

select * from

(select * from member where data!=”order by time desc limit 0,10

)a

where data like’%$keyword%’

It is also wrong to replace T with a: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in

Please help me to have a look again! Thanks

#5


$sql=”select * from member where `data` like ‘%$keyword%’ order by `time` desc Limit 0,10″;

#6


What is your code, what version of MYSQL

#7


Quoting the reply from the 5th floor:

$sql=”select * from member where `data` like ‘%$keyword%’ order by `time` desc Limit 0,10″;

At the beginning, I thought so too, but this can only get the value of data=$keyword, for example, if there are a thousand pieces of data, it will search for the first 10 pieces of the total number of pieces containing $keyword. And I want to get 10 items in reverse order first, and then compare how many of these 10 items contain $keyword

#8


Quoting the reply from the 6th floor:

What is your code, what version of MYSQL

It has nothing to do with the code:

$query=”select * from

(select * from member where data!=”order by time desc limit 0,10

)a

where data like’%$keyword%’

“;

$result=$obj_db->simplequery($query);

while ($arr=$obj_db->fetchrow($result,DB_FETCHMODE_ASSOC))

{

$list.=”$arr[data]
“;

}

MYSQL installed and debugged locally, a bit old:

MySQL 4.0.24-nt

#9


So what’s wrong with your code. Your data and time fields are reserved words and need to be escaped with `data` `time`.

#10


Could it be that a mysql statement cannot be completed? Can you output 10 first:

select * from member where data!=” order by time desc Limit 0,10

Output 10, and then

foreach ($list as $v){

Compare the same data as $keyword to get $count

}

if ($count>0){

echo “”;

exit();

}

Only thinking, which expert can write out the code?

Or is there an easier way?

#11


Quoting the reply from the 9th floor:

So what’s wrong with your code. Your data and time fields are reserved words and need to be escaped with `data` `time`.

It has nothing to do with this, it is also wrong to change the whole to `mydata` `mytime`:

select * from

(select * from member where mydata!=”order by mytime desc limit 0,10

)a

where mydata like’%$keyword%’

#12


You do not provide error information. Who knows what went wrong.

Processing in php is also possible.

$count=0;

foreach ($list as $v){

if($v==$keyword) $count++;

}

if ($count>0){

echo “”;

exit();

}

#13


Quoting the reply from the 12th floor:

You do not provide error information. Who knows what went wrong.

Processing in php is also possible.

$count=0;

foreach ($list as $v){

if($v==$keyword) $count++;

}

if ($count>0){

echo “”;

exit();

}

#16


$list.=”$arr[data]”; Change to

$list[]=$arr[data];

#17


Quoting the reply from the 16th floor:

$list.=”$arr[data]”; Change to

$list[]=$arr[data];

Thanks, success, give points

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/mysql-queries-whether-the-first-ten-rows-of-data-sorted-in-reverse-order-contain-a-certain-key-word-please-help-solve-it-by-php-experts-thank-you/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: 34331943@QQ.com

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索