gpt4 book ai didi

即使查询相同,PHP 返回的结果也少于 phpmyadmin

转载 作者:行者123 更新时间:2023-11-29 03:06:37 24 4
gpt4 key购买 nike

当我在 phpmyadmin 中运行以下查询时,我得到了 18 个结果 - 所有这些都是正确的,也是我正在寻找的。但是,当我将查询复制并粘贴到一个 php 文件并运行该页面时,我得到了 17 个结果。

SELECT 
ta.jobTaskID,
jt.customTaskTitle, jt.taskID, jt.status,
d.dealershipName,
j.jobNumber, j.jobID, j.title, j.jobSpec,
wt.taskName,
po.dueToProduction
FROM taskassignments ta
INNER JOIN jobTasks jt ON ta.jobTaskID = jt.jobTaskID
INNER JOIN jobs j ON jt.jobID = j.jobID
INNER JOIN dealerships d ON j.dealershipID = d.dealershipID
LEFT JOIN workflowtasks wt ON jt.taskID = wt.taskID
LEFT JOIN purchaseorders po ON j.jobID = po.jobID
WHERE ta.userID = 1 AND jt.status != 'Completed';

编辑:Here's a snapshot of my phpmyadmin resulthere's a snapshot of my var_dump .

这是我的 PHP 代码(我使用了我创建的数据库类)

$myTasks = $connection->runQuery("
SELECT
ta.jobTaskID,
jt.customTaskTitle, jt.taskID, jt.status,
d.dealershipName,
j.jobNumber, j.jobID, j.title, j.jobSpec,
wt.taskName,
po.dueToProduction
FROM taskassignments ta
INNER JOIN jobTasks jt ON ta.jobTaskID = jt.jobTaskID
INNER JOIN jobs j ON jt.jobID = j.jobID
INNER JOIN dealerships d ON j.dealershipID = d.dealershipID
LEFT JOIN workflowtasks wt ON jt.taskID = wt.taskID
LEFT JOIN purchaseorders po ON j.jobID = po.jobID
WHERE ta.userID = " . $userID . " AND jt.status != 'Completed'");

最后,这是连接类用来运行查询的代码:

// runs the user defined query
public function runQuery($runMe)
{
$outArray = array();
if ($this->checkConnection()) // if the connection is a resource
{
$returned = mysql_query($runMe, $this->dbConnection);
if ($returned === false) // if there was an error during sql execution
{
echo "SQL Query error: " . mysql_error();
}

if ($returned === true) // if a update, insert, delete, etc... command was run
return true;
if (is_resource($returned))
{
$outArray = array(); // returned array with query results
for ($i = 0; $i < mysql_num_rows($returned); $i++)
{
$outArray[] = mysql_fetch_assoc($returned);
}
}
if (count($outArray) < 1)
return null;
else
return $outArray;
}
else
echo "Your Database Connection Was Unable To Be Authenticated.";
}

最佳答案

更好的解决方案是根本不使用 mysql_num_rows() ,而只是不断重复调用 mysql_fetch_assoc() 直到它停止返回结果:

$outArray = array();
while ( $row = mysql_fetch_assoc($returned) ) {
$outArray[] = $row;
}

(请注意,您的代码正在使用的 original PHP mysql API 已从 PHP 5.5.0 开始弃用,并将在未来的某个版本中删除。您真的应该移至 one of the supported APIs ,即 mysqliPDO 。)

关于即使查询相同,PHP 返回的结果也少于 phpmyadmin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14143467/

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