我相信這應該爲你做的伎倆。只需在頁面的某個地方包含兩個函數,然後在要顯示列表時調用showQuestionsAndResponses();
。顯然你可能想要調整回顯語句以使其以更有吸引力的方式打印所有內容。
function showQuestionsAndResponses() {
$query = "SELECT * FROM my_table WHERE resID IS NULL";
$sql_result = mysql_query($query);
while ($row = mysql_fetch_array($sql_result) {
echo $row['title'].": ".$row['text'];
$responses = getResponses($row['IntQID']); //get responses for curr question
foreach($responses as $response) {
echo $response['text']; //print each response
}
}
}
function getResponses($qID) {
if(is_numeric($qID) { //always best to check, just to be sure!
$query = "SELECT * FROM my_table WHERE resID = ".$qID;
$sql_result = mysql_query($query);
$responses = array();
while ($row = mysql_fetch_array($sql_result) {
$responses[] = $row; //add current row to array
}
return $responses; //return the array of responses
}
return false; //return false by default
}
ResID是響應鏈接到的問題的IntQID嗎?這些都在同一個表中嗎? – prodigitalson 2010-08-14 07:21:21
是的,他們在同一張桌子上 – BigMike 2010-08-14 14:51:59