linx_effect Posted December 7, 2009 Share Posted December 7, 2009 Hi Guys, Basically i have 2 tables: - thumbs (this stores all the thumbs on the site) - pages (this stores all the pages on the site) i am trying to establish a link between the thumbs table and the pages table via the page_id on both tables. i've considered using a JOIN in my mysql query but only problem is that not every record from the pages table will have a thumb, which will result in displaying only records that contain thumbs in them. my other solution was to have 2 SELECT queries: - one query for thumbs - one query for pages and then try to combine them using arrays like this: $sql="SELECT * FROM thumbnails"; $result = db_query($sql); while($row=mysql_fetch_array($result)) { $page_id = $row["page_id"]; $thumbnail_name = $row["thumbnail_name"]; $thumbnail_array[$page_id] = array($thumbnail_name); } $sql="SELECT * FROM pages"; $result = db_query($sql); while($row=mysql_fetch_array($result)) { $nav_array[$row['page_id']] = array( 'page_id' => $row['page_id'], 'page_title' => $row['page_title'], 'page_parent_id' => $row['page_parent_id'], 'thumbnail_name' => $thumbnail_array[$page_id] ); } as you can see, i've already tried to combine them but i dont think it works unless i dont know how to output it correctly. to be perferctly honest, i am abit slow when it comes to arrays but hopefully any suggestions or help will just make me a little bit better at it Link to comment https://forums.phpfreaks.com/topic/184263-combining-arrays/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 7, 2009 Share Posted December 7, 2009 i've considered using a JOIN in my mysql query but only problem is that not every record from the pages table will have a thumb, which will result in displaying only records that contain thumbs in them. Not if you use a LEFT JOIN. All the records from the left-hand table will be used, even if there is no matching value in the second or right-hand table. Link to comment https://forums.phpfreaks.com/topic/184263-combining-arrays/#findComment-972766 Share on other sites More sharing options...
linx_effect Posted December 7, 2009 Author Share Posted December 7, 2009 cheers mate, solved my problem with only 1 mysql query Link to comment https://forums.phpfreaks.com/topic/184263-combining-arrays/#findComment-972787 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.