Forum Moderators: coopster

Message Too Old, No Replies

select one photo for each user and display the list

select one photo for each user and display the list

         

riggerz29

8:51 am on Apr 26, 2010 (gmt 0)

10+ Year Member



Hi all

i'm having trouble displaying a list of forklift trucks

basically i have 2 tables one for the forklift truck info and another table to store multiple photos for each truck

when i select the tables and loop the results i am getting the same forklift display twice because it has 2 photos in the photos table but i only want one of each forklift to display here is my code

$sql = "SELECT * FROM tbl_trucks, tbl_truck_photos WHERE tbl_trucks.t_show='1' AND tbl_trucks.t_id=tbl_truck_photos.tp_truckID ORDER BY tbl_trucks.t_id DESC";


any help would be greatfull thanks in advance

Readie

11:55 am on Apr 26, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$sql = 'SELECT DISTINCT(tbl_trucks.t_id), tbl_trucks.truck_name, tbl_truck_photos.image_path FROM tbl_trucks INNER JOIN tbl_truck_photos ON tbl_trucks.t_id = tbl_truck_photos.tp_truckID WHERE tbl_trucks.t_show = 1 ORDER BY tbl_trucks.truck_id DESC';

Try that. I suggest not using " SELECT * " in future by the way, it is slower and consumes more memory than specifying just the columns you want.

riggerz29

3:07 pm on Apr 26, 2010 (gmt 0)

10+ Year Member



Readie thanks so much for your help, worked a treat :)