JSHINER Posted May 1, 2007 Share Posted May 1, 2007 I have two tables that are as follows: Here is TABLE 1: ID SERVICES OTHER_SERV --------------------------------------- 1 A,B,C,E,F B,D,E,G 2 B,D,E E,G,H Here is TABLE 2: Field Short Long ------------------------------------------------ SERVICES A Apples SERVICES B Ball SERVICES C Car SERVICES D Dog SERVICES E Egg SERVICES F Fly OTHER_SERV B Boot OTHER_SERV D Doll OTHER_SERV E Eagle OTHER_SERV G Glass OTHER_SERV H House So what I need is for: ID 1 to display: Apples, Ball, Car, Egg, Fly - Boot, Doll, Eagle, Glass ID 2 to display: Ball, Dog, Egg - Eagle, Glass, House I need the results in TABLE 1 to display based on the references in TABLE 2. Any idea's? I am completely lost here ??? Quote Link to comment https://forums.phpfreaks.com/topic/49395-solved-help-need-to-display-abg-as-apple-ball-glove/ Share on other sites More sharing options...
greatwhitepine Posted May 1, 2007 Share Posted May 1, 2007 This'll do it. <?php function getServiceNames( $arr_service, $arr_serviceDefinitions ) { $arr_serviceNames = array( ); foreach ( $arr_service as $str_serviceNameShort ) { $arr_serviceNames[] = $arr_serviceDefinitions[ $str_serviceNameShort ]; } return $arr_serviceNames; } function constructServiceNamesString( $int_serviceId, $arr_services, $str_serviceType, $arr_serviceDefinitions ) { $str_serviceNames = ''; $arr_serviceNames = getServiceNames( $arr_services[ $int_serviceId ][ $str_serviceType ], $arr_serviceDefinitions[ $str_serviceType ] ); foreach ( $arr_serviceNames as $str_serviceName ) { $str_serviceNames .= $str_serviceName . ', '; } if ( $str_serviceNames ) { $str_serviceNames = substr( $str_serviceNames, 0, -2 ); } return $str_serviceNames; } function displayServiceNames( $int_serviceId, $arr_services, $arr_serviceDefinitions ) { $str_serviceNames = constructServiceNamesString( $int_serviceId, $arr_services, 'services', $arr_serviceDefinitions ); $str_otherServiceNames = constructServiceNamesString( $int_serviceId, $arr_services, 'other_services', $arr_serviceDefinitions ); print 'ID: ' . $int_serviceId . ': ' . $str_serviceNames . ' - ' . $str_otherServiceNames . "\n"; } function displayServices( $arr_services, $arr_serviceDefinitions ) { foreach ( $arr_services as $int_serviceId => $arr_service ) { displayServiceNames( $int_serviceId, $arr_services, $arr_serviceDefinitions ); } } $arr_services[ 1 ] = array( 'services' => array( 'A', 'B', 'C', 'E', 'F' ), 'other_services' => array( 'B', 'D', 'E', 'G' ) ); $arr_services[ 2 ] = array( 'services' => array( 'B', 'D', 'E' ), 'other_services' => array( 'E', 'G', 'H' ) ); $arr_serviceDefinitions[ 'services' ] = array( 'A' => 'Apples', 'B' => 'Ball', 'C' => 'Car', 'D' => 'Dog', 'E' => 'Egg', 'F' => 'Fly' ); $arr_serviceDefinitions[ 'other_services' ] = array( 'B' => 'Boot', 'D' => 'Doll', 'E' => 'Eagle', 'G' => 'Glass', 'H' => 'Glass' ); displayServices( $arr_services, $arr_serviceDefinitions ); ?> Quote Link to comment https://forums.phpfreaks.com/topic/49395-solved-help-need-to-display-abg-as-apple-ball-glove/#findComment-242085 Share on other sites More sharing options...
JSHINER Posted May 1, 2007 Author Share Posted May 1, 2007 How can I get the TABLE 2 to automatically pull from the table? That was just a short sample of the definitions ... There are over 1,000 different rows in that table. Quote Link to comment https://forums.phpfreaks.com/topic/49395-solved-help-need-to-display-abg-as-apple-ball-glove/#findComment-242087 Share on other sites More sharing options...
greatwhitepine Posted May 1, 2007 Share Posted May 1, 2007 I'm not sure I get your meaning however if you know the service id then you can call displayServiceNames( ) directly. Quote Link to comment https://forums.phpfreaks.com/topic/49395-solved-help-need-to-display-abg-as-apple-ball-glove/#findComment-242094 Share on other sites More sharing options...
JSHINER Posted May 1, 2007 Author Share Posted May 1, 2007 I mean here: $arr_serviceDefinitions[ 'other_services' ] = array( 'B' => 'Boot', 'D' => 'Doll', 'E' => 'Eagle', 'G' => 'Glass', 'H' => 'Glass', ); Could that instead call on the TABLE 2 and run a query for other_services? And then display the results as shown there - since there are over 100 or so differnet things that could be in place of other_services. Quote Link to comment https://forums.phpfreaks.com/topic/49395-solved-help-need-to-display-abg-as-apple-ball-glove/#findComment-242099 Share on other sites More sharing options...
greatwhitepine Posted May 1, 2007 Share Posted May 1, 2007 Are you saying that TABLE 1 and TABLE 2 are existing database tables? If so then the same principle applies however you need to fetch the data from the database using SQL commands. Quote Link to comment https://forums.phpfreaks.com/topic/49395-solved-help-need-to-display-abg-as-apple-ball-glove/#findComment-242107 Share on other sites More sharing options...
sasa Posted May 1, 2007 Share Posted May 1, 2007 SELECT TABLE_1.ID, TABLE_2.Long FROM TABLE_2, TABLE_1 WHERE FIND_IN_SET(Short,(SELECT SERVICES FROM TABLE_1)) ORDER BY ID Quote Link to comment https://forums.phpfreaks.com/topic/49395-solved-help-need-to-display-abg-as-apple-ball-glove/#findComment-242136 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.