To explain this I will use an example of the problem I am having. I have a table called images. Here is the setup:
id (unique id)
fileid (this relates it to a certain file)
largeimg (URL of larger image)
smallimg (URL of thumbnail image)
Now, a file can have 0, 1 or even multiple images associated with it. The problem is that if a file has 2 images associated with it:
Code: Select all
id fileid largeimg smallimg
1 1 http://www.example.com/image1.jpg http://www.example.com/thumbnail1.jpg
2 1 http://www.example.com/image2.jpg http://www.example.com/thumbnail2.jpg
(notice fileid is the same for both)Code: Select all
Array
(
їlargeimg] => http://www.example.com/image2.jpg
їsmallimg] => http://www.example.com/thumbnail2.jpg
)Code: Select all
Array
(
їlargeimg] => http://www.example.com/image1.jpg
їsmallimg] => http://www.example.com/thumbnail1.jpg
їlargeimg2] => http://www.example.com/image2.jpg
їsmallimg2] => http://www.example.com/thumbnail2.jpg
)Code: Select all
$sql = "SELECT
f.*, img.*
FROM
files as f,
images as img
WHERE
f.id = 1
AND img.fileid = 1
";