我有一个名为$generic
的变量,它被传递到加载SQL
查询的函数中,这用于与表cms_web_pages
中的slug
列形成匹配;因此,在这个实例中,让我们说$generic
等于'bar',然后查询抓取匹配行的id
,并使用id
来匹配第二个表cms_web_page_content
中的行与列page_id
,然后从表cms_web_page_content
中抓取所有数据放入数组中。
id | title | slug
-----------------
1 | foo | bar
2 | bar | foo
表"cms_web_page_content":id | title | content | position | page_id
-----------------------------------------
1 | foo | bar | 1 | 1
2 | bar | foo | 2 | 1
3 | doh | doh | 1 | 2
SQL查询:$link = db_connect();
$qry = mysqli_query($link,
"SELECT page.*, content.*
FROM cms_web_pages AS page
WHERE page.slug = '".$generic."'
LEFT JOIN cms_web_page_content AS content
ON page.id = content.page_id)
ORDER BY content.position ASC")
or die(mysqli_error($link)
);
$content = array();
提前感谢任何能帮忙的人
Use as :
"SELECT page.*, content.*
FROM cms_web_pages AS page
LEFT JOIN cms_web_page_content AS content
ON (page.id = content.page_id)
WHERE page.slug = '".$generic."'
ORDER BY content.position ASC"