I am creating a 'buy and sell' website as a beginner project in PHP.
I have a 'advert_images', it is 3 columns.
ID | advert_id | path_to_image _|___|_______
the id column is AI and is not used. When I put the data in the database I took the advert_id from when it was posted and just recorded the image paths next to it.
Now on the advert pages I want to output these images... but I can't get my head around writing the function for this. I've been at it a few hours now trying and adapting things I've seen on this site but it won't click...
function get_images($adverts_id){
$query = mysql_query("SELECT * FROM `advert_images` WHERE `advert_id` = " .$adverts_id . "");
while (($row = mysql_fetch_assoc($query)) !== false){
$row['image_path'];
echo ($row['image_path']);
}
}
This is just echoing this:
images/adverts/52f0f5f8cc2c099d0c.jpgimages/adverts/9f1579b69deb751161852.jpgimages/adverts/1d0d4ff0b2c40834c7aa.jpgimages/adverts/8ea518b393eebfd0cd0.jpgimages/adverts/3566957b0d3dfdfa3c.jpg
so it's not a million miles away from working but I want it so I can call each image individually...
Each advert can have anything from 0-5 images saved for it in advert_images
Any help would be greatly appreciated. Like I said I am just stuck and fresh out of ideas :(
mysql_
functions anymore, because they're deprecated; check out PDO or mysqli for the alternative. – Ja͢ck Jul 19 '13 at 8:04