I’m a newbie to MySQL and php and I’m getting wrapped around the axle on this one. I’ve been working on this for hours and can’t get the desired result. Help please? What I am starting with is:
$query = sprintf('select image_id, filename from images');
$result = mysql_query($query);
$images = array();
while ($row = mysql_fetch_array($result)) {
$id = $row['image_id'];
$images[$id] = $row['filename'];
echo $images[$id];
}
I have three tables:
- submissions – submission_id, price, description
- images – image_id, filename, size
- imagsub – image_id, submission_id
The above script is pulling out all the filenames and image_id’s in the database. I need to limit the results to just the images rows that match up with the submission_id’s in the referencing table. Ive tried various JOINS within the sprintf function to no avail and now I cant even get the results I want with a simple mysql_query. Can someone please set me on the right path before I pull my hair out. Do I need to JOIN all three tables here or is it enough to JOIN the images and imagsub tables? I have the submission_id I need in a variable called $item that was pulled from a previous page so maybe I don’t need the submissions table at all, just the foreign key from imagsub?
Have you tried