没有看到你的数据库抽象层($这个 - > 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