Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.