gpt4 book ai didi

php - 使用 mysql LIKE 查询获取多行。在 mysql 中有效,但在 php 中无效

转载 作者:行者123 更新时间:2023-11-29 21:11:02 25 4
gpt4 key购买 nike

这是我的 mysql 查询:

select studentID from GameMaster where hobbies like '%baseball%' and hobbies like '%basketball%';

爱好字段类型-长文本。

这会在 mysql 中获取两个值。 S1001,S1002

当我在 PHP 代码中使用它时,仅获得第一行。

这是我的 php 代码

$sSQL="select studentID from GameMaster where hobbies like '%baseball%' and hobbies like '%basketball%'";

$result = mysqli_query($dbc,$sSQL);

$numberOfRows = mysqli_num_rows($result);

if ($numberOfRows>0) {

for ($i = 0; $i < $numberOfRows; $i++) {

$row = mysqli_fetch_array($result);
$csv_output .= $row[$i].",";
}
$csv_output .= "\n";
}
print $csv_output;

$csv_output 值为 S1001,,

如您所见,第二个是空的。循环是不是错了?我正在将此值导出到应用程序发明者。

最佳答案

试试这个:

$sSQL="select studentID from GameMaster where hobbies like '%baseball%' or hobbies like '%basketball%'";

$result = mysqli_query($dbc,$sSQL);

$numberOfRows = mysqli_num_rows($result);

if ($numberOfRows>0)
{
$row = mysqli_fetch_array($result);
for ($i = 0; $i < $numberOfRows; $i++)
{
$csv_output .= $row[$i].",";
}
$csv_output .= "\n";
}
print $csv_output;

关于php - 使用 mysql LIKE 查询获取多行。在 mysql 中有效,但在 php 中无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36370444/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com