當我在phpmyadmin中運行以下查詢時,我得到18個結果 - 所有這些結果都是正確的,我在找什麼。但是,當我複製&將查詢粘貼到一個php文件並運行該頁面時,我找回了17個結果。即使查詢結果相同,PHP返回的結果也少於phpmyadmin
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 result 和here's a snapshot of my var_dump。
這是我的PHP代碼(我用我創建了一個DB類)
$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.";
}
請顯示您的PHP代碼。 – eggyal
顯示你的php代碼,你可能在某處放置一行。例如做$ row = fetch(); while(...){$ row = fetch();打印$行; }' –