我有一個填充了MySQL查詢結果的表。我需要在表中插入一個額外的列作爲PHP函數,它根據查詢中字段的值生成字符串(我認爲這是如何解決問題的)。這可能嗎?我試圖將列設置爲一個變量,並在該函數中調用該變量(該代碼中未設置爲用戶定義的函數),但是我必須做錯了某些事情,因爲表格根本沒有填充。帶MySQL查詢的PHP函數表
$query1 = "SELECT `rank`.`term`,
`rank`.`acadplan`,
`rank`.`projlvl`, `rank`.`gpa`,
(SELECT COUNT(gpa) FROM `rank1`
WHERE `rank1`.`term` = '{$term}'
AND `rank1`.`acadplan`='{$acadplan}'
AND `rank1`.`projlvl`='{$projlvl}'
AND `rank1`.`gpa` > `rank`.`gpa`) + 1 AS 'ranking',
FROM `rank`
WHERE `rank`.`term` ='{$term}'
AND `rank`.`acadplan`='{$acadplan}'
AND `rank`.`projlvl`='{$projlvl}'
ORDER BY `rank`.`gpa` DESC";
$result = mysqli_query($query1);
echo "<table>";
echo "<th>Term</th>";
echo "<th>Plan</th>";
echo "<th>Level</th>";
echo "<th>GPA</th>";
echo "<th>Rank</th>";
echo "<th>NEWCOL</th>";
echo "<col width = '125'>";
echo "<col width = '125'>";
echo "<col width = '125'>";
echo "<col width = '125'>";
echo "<col width = '125'>";
echo "<col width = '250'>";
$num_rows = mysqli_num_rows($result);
這是一個需要被執行的功能:
if ($num_rows <=24) {
switch ($num_rows) {
case ($rank >=1 and $rank <=3):
echo "1-3";
break;
case ($rank >=4 and $rank <=6):
echo "4-6";
break;
case ($rank >=7 and $rank <=9):
echo "7-9";
break;
case ($rank >=10 and $rank <=12):
echo "10-12";
break;
case ($rank >=13 and $rank <=15):
echo "13-15";
break;
case ($rank >=16 and $rank <=18):
echo "16-18";
break;
case ($rank >=19 and $rank <=21):
echo "19-21";
break;
case ($rank >=22 and $rank <=24):
echo "22-24";
break;
}
} elseif ($num_rows >=25 and $num_rows <=50) {
echo "greater than 24";
} elseif ($num_rows >=51 and $num_rows <=100) {
echo "greater than 50";
} elseif ($num_rows >=101 and $num_rows <=150) {
echo "greater than 100";
} elseif ($num_rows >=151 and $num_rows <=260) {
echo "greater than 150";
}
}
這是表:
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['term'] . "</td>";
echo "<td>" . $row['acadplan'] . "</td>";
echo "<td>" . $row['projlvl'] . "</td>";
echo "<td>" . $row['gpa'] . "</td>";
echo "<td>" . $row['ranking'] . "</td>";
echo "</tr>";
}
echo "</table>";
'mysql_queryi($ query1);'是一個錯字嗎? –
我認爲,這是SO-SO校正前的xD'替代(/^mysql_ /,/^mysqli_ /)SO片段)) –
是的,一個錯誤,固定的。 – user3362278