denoteone Posted July 26, 2010 Share Posted July 26, 2010 Is it possible to build and array from data that is spread across multiple tables in adata base? I am using drupal and I want to create an jquery image slider that is created on the fly by accessing multiple tables and then getting the data and there image path based on a field that is flagged in the table. I know it is a mess but below is my first stab at this. <? include("include/common.php"); $sql = "SELECT node.title AS title, content_type_chicself.field_teaser_self_value AS TeaserSelf, content_type_chicself.field_feature_imageself_value AS ImageSelf, content_type_chicfamily.field_teaser_family_value AS TeaserFamily, content_type_chicfamily.field_feature_image_value AS ImageFamily FROM node,content_type_chicself,content_type_chicfamily WHERE content_type_chicself.nid = node.nid AND content_type_chicfamily.nid = node.nid AND content_type_chicfamily.field_feature_value = 'on' AND content_type_chicself.field_self_feature_value = 'on'"; $db = new connection(); $result = $db->query($sql); $content = array(); while($info = mysql_fetch_array($result)) { $content[] = $info; } for ( $counter = 0; $counter < 10; $counter += 1) { echo '<div id="slider"> <a href=" "/><img src=" '.$content[$counter]['ImageSelf'] .' " alt="" title="'.$content[$counter]['TeaserSelf'] .'" /></a> <a href=" "/><img src=" '.$content[$counter]['ImageFamily'] .' " alt="" title="'.$content[$counter]['TeaserFamily'] .'" /></a> </div>'; } ?> Link to comment https://forums.phpfreaks.com/topic/208886-build-an-array-from-mulitple-tables-of-data/ Share on other sites More sharing options...
Goat Posted July 26, 2010 Share Posted July 26, 2010 I suggest you tackle it as MySQL query problem, not as php problem. It is possible to merge multiple arrays but I suggest you create query that returns already merged array that you want. Google something called LEFT JOIN and RIGHT JOIN to find out how to get values from multiple tables. regards, Goat Link to comment https://forums.phpfreaks.com/topic/208886-build-an-array-from-mulitple-tables-of-data/#findComment-1091124 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.