mysql query array inside array
sorry first for my lousy english ... but i got some question need some advice
how can i get data from database in one query?isit possible get array from
db, inside the main array got another array?
table structure:
user_post -
id int(12) AI unique
uid int(12)
content text
user_image -
filename varchar255
uid int(12)
pid int(12) index
pid->foreign_key user_post.id
ON DELETE CASCADE
ON UPDATE CASCADE
example: for each user_post can contain more than 1 row user_image but
maximum 10 row, how can i select and make it all together in 1 array so i
don't need to run query 2 times like below?
query 2 times to done this example:
$db = new Db('main');
$db->query('SELECT `id`, `uid`, `content` FROM `user_post` WHERE `id` =
:id LIMIT 1');
$db->bind(':id', '1'); //Example
$result = $db->single();
$db->query('SELECT `filename`, `uid`, `pid` FROM `user_image` WHERE `pid`
= :pid LIMIT 10');
$db->bind(':pid', '$result['id']);
$images = $db->resultset();
so the $images will contain all the images filename for the post, anyway
to make it in 1 query?
No comments:
Post a Comment