Jump to content

[SOLVED] HELP: Need to: Display A,B,G as Apple, Ball, Glove


JSHINER

Recommended Posts

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  ???

Link to comment
Share on other sites

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 );

?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.