Multiple copies of the same field name overwrite each other
Posted: Sat May 22, 2004 10:39 am
Wow, haven't been around here in a loooong time but this one has me stumped. I just recently created my first real relational database but I'm having a problem retrieving all the images stored in one of the tables.
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:
but when I query the database it only returns an array like this:
instead of returning both! How can I get it so its more like:
Here is a sample query I am using:
If it's too confusing, please post and i'll try to explain it more clearly. Thank you in advance for any help on this!
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
";