如果我正確理解你的問題。
用於從標題表中檢索細節
第一查詢 =>得到head_id
然後
在類別表第二查詢 =>與比較cat_head head_id並檢索貓的詳細信息。
更新
我使用上述理念爲我定製的論壇。
示例代碼
$result1=queryMysql("SELECT * FROM headers"); //My custom function for query execution, returns the result
while($row1 =$result2->fetch_array(MYSQL_ASSOC))
{
echo $row1['head_name'];
$result2=queryMysql("SELECT * FROM categories WHERE cat_head=$row[head_id]"); // My custom function for query execution, returns the result
while($row2=$result2->fetch_array(MYSQL_ASSOC)){
echo $row2['cat_name'];
echo $row2['cat_description'];
}
}
這就是我的意思。
今天我肯定會嘗試一下JOIN操作。
$result=queryMysql('SELECT * FROM headers LEFT JOIN categories ON head_id = cat_head'); //My custom function for query execution, returns the result
$new_head="";
$pre_head="";
while($row =$result->fetch_array(MYSQL_ASSOC))
{
$new_head= $row['head_name'];
if($new_head!=$pre_head){
echo $new_head;
}
if($row['cat_name']!=null or $row['cat_description']!=null){
echo $row['cat_name'];
echo $row['cat_description'];
}
else {
echo "No categories yet";
}
$pre_head=$row['head_name'];
}
我覺得你有這個想法了。
改進格式並直接在帖子中添加圖片。 – AdrienXL