php - mysql LIKE 三个匹配时只返回一行

标签 php mysql

当我在我的文件 search.php 中使用以下内容查询我的数据库时,它只返回它遇到的第一个结果。

$qry = "SELECT business_id FROM business WHERE zip like '%91326%'";

$rs = mysql_query($qry);
$rec = mysql_fetch_array($rs);
echo $session->showContents($rec);

showContents 只是一个实用函数...

function showContents($array)
{
        echo "<pre>";
        print_r($array);
        echo "</pre>";
}

showContents 返回了这个:

Array
(
    [0] => 3
    [business_id] => 3
)

疯狂的是,当我在 sqlbuddy 中输入相同的查询时,它会给我:

business_id
3
5
6

我很迷茫

最佳答案

mysql_fetch_array只获取一行。您想多次使用它来构建一个包含整个结果集的数组:

$rec = array();

while(($row = mysql_fetch_array($rs)) !== FALSE) {
    $rec[] = $row;
}

如果您只想要 ID,请选择 ID:

$rec = array();

while(($row = mysql_fetch_array($rs)) !== FALSE) {
    $rec[] = $row[0];
}

关于php - mysql LIKE 三个匹配时只返回一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1332057/

相关文章:

javascript - 如何使用 PHP ajax JQUERY 创建 3 个依赖下拉列表?

php orm够不够强大?

php - 为什么mysql查询只返回一行

php - 奇怪的字符 PHP\u00a3 而不是 £

php - 如何从<select>中获取值并放入sql查询中?

php - PHP 中检查元素不包含特定 src 属性的 Xpath

php - View 不反射(reflect)数据库的更新

php - Mysql_fetch_data 意外打印

mysql - 如何按天选出今天和明天少于指定时间的数据?

mysql - 列出以特定字母开头的 mysql 表