我目前有这个 SQL 语句:
SELECT p.*,k.name FROM posts AS p
LEFT JOIN `post-keywords` AS pk ON p.id = pk.id_post
LEFT JOIN keywords AS k ON pk.id_keyword = p.id
ORDER BY p.id DESC LIMIT :num,:count
但是,它没有按预期工作。这是服务器返回的内容:
array(7) {
[0]=>
array(5) {
["id"]=>
string(1) "2"
["title"]=>
string(28) "Everything about Internet"
["text"]=>
string(41) "Article itself"
["date"]=>
string(1) "0"
["name"]=>
NULL
}
[1]=>
array(5) {
["id"]=>
string(1) "1"
["title"]=>
string(16) "Internet"
["text"]=>
string(32) "Text text text"
["date"]=>
string(10) "1371186330"
["name"]=>
string(7) "tag1"
}
[2]=>
array(5) {
["id"]=>
string(1) "1"
["title"]=>
string(16) "Internet"
["text"]=>
string(32) "Text text text"
["date"]=>
string(10) "1371186330"
["name"]=>
string(7) "tag2"
}
[3]=>
array(5) {
["id"]=>
string(1) "1"
["title"]=>
string(16) "Internet"
["text"]=>
string(32) "Text text text"
["date"]=>
string(10) "1371186330"
["name"]=>
string(7) "tag3"
}
[4]=>
array(5) {
["id"]=>
string(1) "1"
["title"]=>
string(16) "Internet"
["text"]=>
string(32) "Text text text"
["date"]=>
string(10) "1371186330"
["name"]=>
string(7) "tag4"
}
[5]=>
array(5) {
["id"]=>
string(1) "1"
["title"]=>
string(16) "Internet"
["text"]=>
string(32) "Text text text"
["date"]=>
string(10) "1371186330"
["name"]=>
NULL
}
[6]=>
array(5) {
["id"]=>
string(1) "1"
["title"]=>
string(16) "Internet"
["text"]=>
string(32) "Text text text"
["date"]=>
string(10) "1371186330"
["name"]=>
NULL
}
}
name
如何从服务器中检索包含多个字段的数组:
array (5) {
["id"] =>
string (1) "1"
["title"] =>
string (16) "Internet"
["text"] =>
string (32) "text text text"
["date"] =>
string (10) "1371186330"
["name"] =>
string (10) "word1"
["name"] =>
string (10) "word2"
["name"] =>
string (10) "word3"
}