Jump to content

query involving LIKE (i think)


Lodius2000

Recommended Posts

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

 

 

Link to comment
https://forums.phpfreaks.com/topic/129890-query-involving-like-i-think/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.