Lodius2000 Posted October 24, 2008 Share Posted October 24, 2008 I think this query would involve like i have a table of image data, captions, credits, img tags, etc that looks like this $sql = "CREATE TABLE `image` ( `id` int(10) NOT NULL, //a unique id and contained in the array $photos `article_id` int(10) NOT NULL, // values are the same as the article id in another table, and $id (see further down) `image_url` varchar(255) NOT NULL, `thumb_url` VARCHAR( 255 ) NOT NULL, `credit` VARCHAR( 255 ) NOT NULL, `image_caption` text NOT NULL )"; in the next code $row['imgorder'] comes from a query to the other table containing article_id, a field that stores the `id` field from the table `image` i have this in there so you can change the order that the photos are displayed so $row['imgorder'] could contain '1,5,2,3,4,6' so that the order you upload a photo is not necessarily the order it is displayed and then i turn it into the array $photos with explode() $photos = explode(",", $row['imgorder']); question is how do i retrieve all of the photos in one query from the array here is what i am thinking "SELECT img_url, credit, image_caption FROM image WHERE article_id = $id AND id LIKE $photos" but i think this will only return 1 result, that of $photos[0], i need it to return a nested array so i can do a foreach and place the retrieved column into the webpage, with only 1 query, the other option is to do a foreach on $photos with a query within the foreach that look like "SELECT img_url, credit, image_caption FROM image WHERE article_id = $photos" but doing it that way could potentially slow things down quite a bit, with that many queries and all I use a dba that supports place holders and the like so syntax may be slightly off. and i can put in my own mysql functions thanks very much Quote Link to comment https://forums.phpfreaks.com/topic/129890-query-involving-like-i-think/ Share on other sites More sharing options...
Barand Posted October 24, 2008 Share Posted October 24, 2008 if $row['imgorder'] contains '1,4,3,2,5' then SELECT ... WHERE id IN ({$row['imgorder']}) Quote Link to comment https://forums.phpfreaks.com/topic/129890-query-involving-like-i-think/#findComment-673510 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.