本文介绍了阵列在MySQL WHERE样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要数组列表选择。 $ ARRAY_NAME 包含:

 阵列([0] => gum.cn [1] =方式> lol.com [2] => ns1.blar.com [3] => test.com [4] => web.cn.)

Why don't the above work? I search other example and the question is asking without using LIKE clause so no solution there. Please help, thanks in advance.

解决方案

It doesn't work because your query will expand to:

SELECT url FROM `PHP`.`db` WHERE url LIKE '%gum.cn,lol.com.,ns1.blar.com...%'

You have to modify your query a little:

$query_parts = array();
foreach ($array_name as $val) {
    $query_parts[] = "'%".mysql_real_escape_string($val)."%'";
}

$string = implode(' OR url LIKE ', $query_parts);

$tank = "SELECT url FROM `PHP`.`db` WHERE url LIKE {$string}";

这篇关于阵列在MySQL WHERE样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 11:50