沒有看到你的數據庫抽象層($這個 - > DB)的確,這裏是從例1的調整代碼the mysql_fetch_assoc documentation
<?php
// replace as you see fit
$sub1 = 'CS1';
// replace localhost, mysql_user & mysql_password with the proper details
$conn = mysql_connect("localhost", "mysql_user", "mysql_password");
if (!$conn) {
echo "Unable to connect to DB: " . mysql_error();
exit;
}
if (!mysql_select_db("mydbname")) {
echo "Unable to select mydbname: " . mysql_error();
exit;
}
$sql = 'SELECT `dSubject_id` ';
$sql .= 'FROM `tbl_subject_details` ';
$sql .= "WHERE `dSubjectCode` ='$sub1';";
$result = mysql_query($sql);
if (!$result) {
echo "Could not successfully run query ($sql) from DB: " . mysql_error();
exit;
}
if (mysql_num_rows($result) == 0) {
echo "No rows found, nothing to print so am exiting";
exit;
}
while ($row = mysql_fetch_assoc($result)) {
echo $row['dSubject_id'];
}
mysql_free_result($result);
?>
設我知道輸出是什麼,我猜它會說:6
知道'$ sub1'中的內容可能會有所幫助 - 或者做整個查詢的迴應也可以;-) – 2010-01-04 13:17:24
@pascal $ sub1是一個代表主題名稱的字符串 – Saranya 2010-01-04 13:21:28
Martin提出的問題是:你會得到什麼回聲$ SUB1;並echo $查詢; – 2010-01-04 13:23:41