0

我有一个名为的变量$generic,它被传递到加载查询的函数中,用于与表中的列SQL形成匹配;所以在这种情况下,让我们说等于'bar',然后查询获取匹配行的 并使用 将第二个表中的行与列匹配,然后从表中获取所有数据以放置在数组中。slugcms_web_pages$genericididcms_web_page_contentpage_idcms_web_page_content

表“cms_web_pages”:

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();

提前感谢任何可以提供帮助的人。

4

1 回答 1

1
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"
于 2013-04-24T11:04:54.797 回答