Jump to content

Need Help With Logic


Go to solution Solved by Ch0cu3r,

Recommended Posts

Logic problem:  Current directory listing at: http://www.nmlta.org/MemberDirectory/bern_member_list.php shows the format I need.  The only way I have previously been able to accomplish that format is by running four separate queries in a loop, which I understand is not good.  Trying to simplify this, I need to explain my data. There are companies, and contact people at those companies, and some companies have branches, and most branches have contact people at them.

There are four tables: company, co_contact, branch, br_contact. The company, co_contact and branch tables all have a field called “company_id” to match the ones that go together, and the branch table also has a “branch_id” field to match with the people in the br_contact table.

I am successful with running separate JOIN queries for company/co_contact matching on “company_id”, and for branch/br_contact matching on “branch_id”, and have successful processes for listing the data properly.

My problem is I can’t find the logic to run them all in one query or loop that will produce the desired output I’m getting with my current four-query mess. The process should go like this:

  1. List company1 info
  2. List all contacts at company1
  3. List branch1 connected to company1 (if applicable)
  4. List all contacts at branch1 of company1
  5. List branch2 connected to company1 (if applicable)
  6. List all contacts at branch2 of company1
  7. Etc. until all branches are listed for company1
  8. Start over with company2…

Here is the code for my first attempt:

<?php

function listCompany($row) {
    echo $row['comp_name'],"<br />";
	if (!empty($row['comp_uw'])) {
	echo $row['comp_uw'],"<br />";}
	echo "</b>",$row['comp_street'],"<br />";
	if (!empty($row['comp_pobox'])) {
	echo $row['comp_pobox'],"<br />";}
	echo $row['comp_csz'],"<br />";
	echo $row['comp_ph'],"&nbsp&nbsp Fax: ",$row['comp_fx'],"<br />";
	if (!empty($row['comp_tfree'])) {
	echo "Toll Free: ",$row['comp_tfree'],"<br />";}
	if (!empty($row['comp_email'])) {
	echo "Email: <a href='mailto:",$row['comp_email'],"'>",$row['comp_email'],"</a><br />";}
	if (!empty($row['comp_web'])) {
	echo "<a href='http://",$row['comp_web'],"' target='_blank'>",$row['comp_web'],"</a><br />";}
	echo "</p>";
}

function listBranch($row2) {
	if (!empty($row2['br_name'])) {
	echo "<p>&nbsp&nbsp&nbsp&nbsp <b>",$row2['br_name'],"</b><br />";}
	echo "&nbsp&nbsp&nbsp&nbsp ",$row2['br_street'],"<br />";
	echo "&nbsp&nbsp&nbsp&nbsp ",$row2['br_csz'],"<br />";
	echo "&nbsp&nbsp&nbsp&nbsp ",$row2['br_ph'],"&nbsp&nbsp ",$row2['br_fx'],"<br /></p>";
}

function listContact($row) {
    if (!empty($row['cont_name'])) {
	echo "<p>&nbsp&nbsp&nbsp&nbsp <b>",$row['cont_name'],"</b>, ",$row['cont_title'],"<br />";}
	if (!empty($row['cont_email'])) {
	echo "&nbsp&nbsp&nbsp&nbsp Email: <a href='mailto:",$row['cont_email'],"'>",$row['cont_email'],"</a><br />";}
	echo "</p>";
}

function listBranchContact($row2) {
    if (!empty($row2['cont_name'])) {
	echo "<p>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp <b>",$row2['cont_name'],"</b>, ",$row2['cont_title'],"<br />";}
	if (!empty($row2['cont_email'])) {
	echo "&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp Email: <a href='mailto:",$row2['cont_email'],"'>",$row2['cont_email'],"</a><br />";}
	echo "</p>";
}

// Connection to DB
$mysqli = new mysqli("localhost", "nmlta_admin", "trooper", "nmlta_agents");
if($mysqli->connect_errno > 0){
    die('Unable to connect to database [' . $db->connect_error . ']');
}

// Retrieve all the data from the "company" table for County and join matching people from the "co_contact" table
$query = "SELECT * FROM company LEFT JOIN co_contact ON company.company_id = co_contact.company_id WHERE comp_county = 'BERNALILLO' ORDER BY company.comp_name, co_contact.cont_rank"; 

$result = $mysqli->query($query) or die($mysqli->error.__LINE__);

// Initialize variable
$lastCompany = '';

// Start building the table to show results
echo "<table border='1' cellpadding='10' cellspacing='0' bgcolor='#f0f0f0' style='margin-left:100px; margin-bottom:20px'>";

// Begin the Company "while" loop for rows in the $result

while($row = $result->fetch_assoc()) { // Company - Loop 1

    // Check if this is a different company than the last one
    if ($lastCompany != $row['company_id']) { // New Company Check - Loop 2
    
    // If this is a different company - change the $lastCompany variable   
    $lastCompany = $row['company_id'];
    
    echo "<tr><td><p><b>";
    // List the company info only if it is not the $lastCompany
    listCompany($row);
	
    } // End New Company Check - Loop 2
    
	// List all Contacts in the Company
	
    listContact($row);
    
    if ($row[next($row['company_id'] != $lastCompany)]) {
		// Start Branch
		// Retrieve all the data from the "branch" table for County and join matching people from the "br_contact" table
$query2 = "SELECT * FROM branch LEFT JOIN br_contact ON branch.branch_id = br_contact.branch_id WHERE company_id = '".$row['company_id']."' ORDER BY branch.comp_name, branch.br_street, br_contact.cont_rank"; 

$result2 = $mysqli->query($query2) or die($mysqli->error.__LINE__);

// Initialize variable
$lastBranch = 'xxx'; //Initialize $lastBranch variable 

// Begin the Branch "while" loop for rows in the $result2
while($row2 = $result2->fetch_assoc()) { // Branch - Loop 1
	
   // Check if this is a different branch than the last one
    if ($lastBranch != $row2['branch_id']) { // New Branch Check - Loop 2
    
    // If this is a different branch - change the $lastBranch variable   
    $lastBranch = $row2['branch_id'];
    
    echo "<tr><td>";
    // List the branch info only if it is not the $lastBranch
    listBranch($row2);
	
    } // End New Branch Check - Loop 2
    
	// List all Contacts in the Branch
	
	listBranchContact($row2);
		
	} // End Branch - Loop 1

	}
		
	} // End Company - Loop 1
		
	echo "</td></tr>";

// Free result set
mysqli_free_result($result);

echo "</table>";

mysqli_close($mysqli);

?>

My first thought was to insert the "if ($row[next($row['company_id'] != $lastCompany)]) {" qualifier after listing the contact for the company being processed, that way when I know a new company is on the next row, I can pause and run my second query to find any applicable branches that match the current company_id.  The syntax must be wrong the way I have it, because I get an error with this, saying: "Fatal error: Only variables can be passed by reference in..." referencing that call in my code. I don't know if there is a syntax change that would make this work, or not.

 

I have thought about, and tried different ways to run a query using JOIN on all four of my tables, but the resulting rows do not correspond with the order in which I need to process them, if that makes sense.  I am not opposed to any suggestions that will make this work - I just can't seem to think it through and find the correct solution, if there is one. The difficulty seems to me to be that the process of listing company/contact info needs to know when it has reached the last row containing a contact tied to the company, so that the branch routine can be processed for the same company.  Any help or suggestions would be appreciated.  Thanks!

Link to comment
https://forums.phpfreaks.com/topic/290736-need-help-with-logic/
Share on other sites

You can get everything in one query, and then use the your:

if ($row[next($row['company_id'] != $lastCompany)]) {

 Try using a LEFT JOIN, that way if there are no branches, then the company will still show up.  You will need to check and see if there is a branch listed, but that should be easy using a:

if(!empty($row['branch_id'])) { ... }

@jcbones

 

This code looked promising:

if ($row[next($row['company_id'] != $lastCompany)]) {

But when it tries to run there is an error: "Fatal error: Only variables can be passed by reference in <filename>"

 

I don't know what the error means or how to fix... any help is appreciated.  Thanks!

Edited by spock9458

@spock9458

Is the same problem you posted a year ago located here? Psyco's provided you with code to achieve this already here has he not?

 

 

 

 

But when it tries to run there is an error: "Fatal error: Only variables can be passed by reference in <filename>"

You are getting that error because you are using next() in correctly. You are passing it a conditional expression not a variable.

Yes, I had forgotten that he suggested a solution - I tried to get his code to work now (after revising it to modern 'mysqli' format) but I am running into problems - probably because I don't understand the "loading" of the array.  Here is my edited code:

<?php
// Connection to DB

$mysqli = new mysqli("localhost", "username", "password", "database");
if($mysqli->connect_errno > 0){
    die('Unable to connect to database [' . $db->connect_error . ']');
}

// Retrieve ALL the "company" specific data (including contacts)
$query = "SELECT *
          FROM company
          LEFT JOIN co_contact
            ON company.company_id = co_contact.company_id
          WHERE comp_county = 'BERNALILLO'
          ORDER BY company.comp_name, co_contact.cont_rank";

$result = $mysqli->query($query) or die($mysqli->error.__LINE__);

// Build the $company_array
$company_array = array();
while($row = $result->fetch_assoc())
{
    if(!isset($company_array[$row['company_id']]))
    {
        //Add the company specific data here
        $company_array[$row['company_id']] = array(
            'name'    => $row['comp_name'],
            'address' => $row['address'],
            'phone'   => $row['phone'],
            'fax'     => $row['fax'],
            'web'     => $row['web'],
            'email'   => $row['email']
        );
    }

    //Add the company contact info here
    $company_array[$row['company_id']]['contacts'][] = array(
        'name' => $row['contact_name'],
        'title' => $row['title'],
        'email' => $row['email']
    );
}

//Run query to get branch info - for ALL companies
$query = "SELECT branch.*, br_contact.*
          FROM branch
          JOIN company ON branch.company_id = company.company_id
          LEFT JOIN br_contact
            ON branch.branch_id = br_contact.branch_id
          WHERE company.comp_county = 'BERNALILLO'
          ORDER BY company.comp_name, branch.br_street, br_contact.cont_rank";

$result = $mysqli->query($query) or die($mysqli->error.__LINE__);

//Add branch (and branch contacts) results to $company_array
while($row = $result->fetch_assoc())
{
    $compID = $row['company_id'];
    $branchID = $row['branch_id'];
    if(!isset($company_array['']['branches'][$row['branch_id']]))
    {
        $company_array[$compID]['branches'][$branchID] = array(
            'branch_name' => $row['branch_name'],
            'address'     => $row['address'],
            'phone'       => $row['phone'],
            'fax'         => $row['fax'],
            'web'         => $row['web'],
            'email'       => $row['email']
        );
    }

    $company_array[$compID]['branches'][$branchID]['contacts'][] = array(
        'name' => $row['contact_name'],
        'title' => $row['title'],
        'email' => $row['email']
    );
}


// Start building the table for showing results
echo "<table border='1' cellpadding='10' cellspacing='0' bgcolor='#f0f0f0' style='margin-left:100px; margin-bottom:20px'>";

// Begin the "foreach" loop for rows in the $company_array

foreach($company_array as $company)
{
    echo "<tr><td>\n";
    echo "<b>{$company['company_name']}</b><br>\n";
    echo "{$company['address']}<br>\n";
    echo "{$company['phone']} Fax: {$company['phone']}><br>\n";
    echo "Email: {$company['email']}<br>\n";
    foreach($company['contacts'] as $contact)
    {
        echo "<b>{$contact['contact_name']}</b>, {$contact['title']}<br>\n";
        echo "Email: {$contact['email']}<br>\n";
    }

    foreach($company['branches'] as $branch)
    {
        echo "<b>Branch {$branch['branch_name']}</b><br>\n";
        echo "{$branch['address']}<br>\n";
        echo "{$branch['phone']} Fax: {$branch['phone']}><br>\n";
        echo "Email: {$branch['email']}<br>\n";
        foreach($branch['contacts'] as $contact)
        {
            echo "<b>{$contact['contact_name']}</b>, {$contact['title']}<br>\n";
            echo "Email: {$contact['email']}<br>\n";
        }
    }
    echo "</td></tr>\n";
}
echo "</table>";

mysqli_close();

?>

I'm getting warnings on these two lines:

 foreach($company['contacts'] as $contact)

and

 foreach($company['branches'] as $branch)

I know it's probably because I don't understand everything that is happening, so if anyone can suggest corrections, I would appreciate.  Thanks!

When asking for help with a warning/error, you need to post the entire error message here. It will help us help you more quickly (and correctly).

 

My guess is that $company['contacts'] and $company['branches'] are not arrays at the point that you get the warning. If you look closely at your collection code, when you first spot a company you don't include those sub-arrays in the company creation:

 

    if(!isset($company_array[$row['company_id']]))
    {
        //Add the company specific data here
        $company_array[$row['company_id']] = array(
            'name'    => $row['comp_name'],
            'address' => $row['address'],
            'phone'   => $row['phone'],
            'fax'     => $row['fax'],
            'web'     => $row['web'],
            'email'   => $row['email'] ,
// Add these lines AND THE COMMA above
'contacts' => array(),
'branches' => array()
        );
In addition, during the branch collection you have a small logic error:

    $compID = $row['company_id'];
    $branchID = $row['branch_id'];
// YOU SHOULD HAVE $compID in the first subscript - where you have ''
    if(!isset($company_array['']['branches'][$row['branch_id']]))
    {
        $company_array[$compID]['branches'][$branchID] = array(
Also, since you grabbed the $compID and $branchID, why not go ahead and use them in that if statement?

OK, I'm working on this code, and it's getting confusing because I've changed my data structure a bit. I have it partially working with this new code:

// Retrieve ALL the "company" specific data (including contacts)
$query = "SELECT *
          FROM company
          LEFT JOIN co_contact
            ON company.company_id = co_contact.company_id
          WHERE comp_county = 'BERNALILLO'
          ORDER BY company.comp_name, co_contact.cont_rank";

$result = $mysqli->query($query) or die($mysqli->error.__LINE__);

// Build the $company_array
$company_array = array();
while($row = $result->fetch_assoc())
{
    if(!isset($company_array[$row['company_id']]))
    {
        //Add the company specific data here
        $company_array[$row['company_id']] = array(
            'name'    => $row['comp_name'],
            'street' => $row['comp_street'],
            'csz'	=>	$row['comp_csz'],
            'phone'   => $row['comp_ph'],
            'fax'     => $row['comp_fx'],
            'web'     => $row['comp_web'],
            'email'   => $row['comp_email'],
            //'branches'		=>	array(),
            //'br_contacts'	=>	array()
            );
    }

    //Add the company contact info here
    $company_array[$row['company_id']]['co_contacts'][] = array(
        'name' => $row['cont_name'],
        'title' => $row['cont_title'],
        'email' => $row['cont_email']
    );
}

//Run query to get branch info - for ALL companies
$query = "SELECT branch.*, br_contact.*
          FROM branch
          JOIN company ON branch.company_id = company.company_id
          LEFT JOIN br_contact
            ON branch.branch_id = br_contact.branch_id
          WHERE company.comp_county = 'BERNALILLO'
          ORDER BY company.comp_name, branch.br_street, br_contact.cont_rank";

$result = $mysqli->query($query) or die($mysqli->error.__LINE__);

//Add branch (and branch contacts) results to $company_array
while($row = $result->fetch_assoc())
{
    $compID = $row['company_id'];
    $branchID = $row['branch_id'];
    if(!isset($company_array[$compID]['branches'][$row['branch_id']]))
    {
        $company_array[$compID]['branches'][$branchID] = array(
            'branch_name' => $row['branch_name'],
            'street'     => $row['br_street'],
            'csz'		=>	$row['br_csz'],
            'phone'       => $row['br_ph'],
            'fax'         => $row['br_fx']
        );
    }

    $company_array[$compID]['branches'][$branchID]['br_contacts'][] = array(
        'name' => $row['cont_name'],
        'title' => $row['cont_title'],
        'email' => $row['cont_email']
    );
}


// Start building the table for showing results
echo "<table border='1' cellpadding='10' cellspacing='0' bgcolor='#f0f0f0' style='margin-left:100px; margin-bottom:20px'>";

// Begin the "foreach" loop for rows in the $company_array

foreach($company_array as $company)
{
    echo "<tr><td>\n";
    echo "<b>{$company['name']}</b><br>\n";
    echo "{$company['street']}<br>\n";
    echo "{$company['csz']}<br>\n";
    echo "{$company['phone']} Fax: {$company['fax']}<br>\n";
    if(!empty($company['web'])) {
    echo "{$company['web']}<br>\n";}
    if(!empty($company['email'])) {
	echo "Email: {$company['email']}<br><br>\n";}
    
    foreach($company['co_contacts'] as $co_contact)
    {
        echo "<b>{$co_contact['name']}</b>, {$co_contact['title']}<br>\n";
     	if(!empty($co_contact['email'])) {
		echo "Email: {$co_contact['email']}<br>\n";}
		echo "<br>";
		
	}
    

    foreach($company['branches'] as $branch)
    {
        echo "<b>{$branch['branch_name']}</b><br>\n";
        echo "{$branch['street']}<br>\n";
        echo "{$branch['csz']}<br>\n";
        echo "{$branch['phone']} Fax: {$branch['fax']}><br>\n";
        echo "Email: {$branch['email']}<br>\n";
        foreach($branch['br_contacts'] as $br_contact)
        {
            echo "<b>{$br_contact['name']}</b>, {$br_contact['title']}<br>\n";
            echo "Email: {$br_contact['email']}<br>\n";
        }
    }
    echo "</td></tr>\n";
}
echo "</table>";

Which produces the listing shown here:

http://www.nmlta.org/NewMemDir/bern_psycho-test2.php

 

It is showing "Invalid Arguments" on lines 118 and 128, which are:

foreach($company['co_contacts'] as $co_contact)

and

foreach($company['branches'] as $branch)

I think I can work it out, but I'm not sure what is the purpose behind the following two statements:

 if(!isset($company_array[$compID]['branches'][$row['branch_id']]))

and

if(!isset($company_array[$row['company_id']]))

I can't really understand why I'm getting the invalid argument errors... I will appreciate any help, and apologize for my ignorance.  Thanks.

  • Solution

The code appears to be working. I think the issue is the $company_array is not being constructed correctly. 

 

Which I think is being caused by the first query. Due to the join on the co_contact table. When a contact is not found all the contact table field values will be returned as null.

 

As seen below (company 1 has 1 contact but company 2 has no contacts)

+------------+-----------+-----+------------+--------------------+-----+
| company_id | comp_name | ... | company_id |     cont_name      | ... |
+------------+-----------+-----+------------+--------------------+-----+
| 1          | Company 1 | ... | 1          | Company1 Contact 1 | ... |
| 2          | Company 2 | ... | NULL       | NULL               | ... |
+------------+-----------+-----+------------+--------------------+-----+ 

Notice the the company_id field is returned twice, The first instance is the value from the company table the second instance is the value from the co_company table.

 

On the second row the second instance for company_id is null because a contact for Company 2 was not found. Here lies the issue.

 

Now when PHP processes the results only the last instance of the company_id field will be returned from the row.

 

In the code $row['company_id'] is used as the array key for grouping the companies data into arrays. For Company 2 $row['company_id'] will be null and not 2 (the value it should be) so the details for that company are not going to be grouped correctly. After the first query being processed the $company_array array will look like this

Array
(
    [1] => Array
        (
            [name] => Company 1
            [street] => 1 Street, NYC
            [csz] => csz 1
            [phone] => 111222330
            [fax] => 111222339
            [web] => http://company1.com
            [email] => inbox@company1.com
            [branches] => Array
                (
                )

            [co_contacts] => Array
                (
                    [0] => Array
                        (
                            [name] => Company1 Contact 1
                            [title] => Company1 Contact 1 Title
                            [email] => contact1@company1.com
                        )

                )

        )

    [] => Array
        (
            [name] => Company 2
            [street] => 2 Street, NYC
            [csz] => csz 2
            [phone] => 222334440
            [fax] => 222334448
            [web] => http://company2.com
            [email] => inbox@company2.com
            [branches] => Array
                (
                )

            [co_contacts] => Array
                (
                    [0] => Array
                        (
                            [name] => 
                            [title] => 
                            [email] => 
                        )

                )

        )

)

When we start together the branches details for each company the data will become malformed. And you get the result you are getting currently.

 

To solve the issue we need to explicitly state the fields we want to return from the co_company table. The first query can be changed to

// Retrieve ALL the "company" specific data (including contacts)
$query = "SELECT company.*,                 # return all fields in the company table
                 co_contact.cont_name,      # return the following fields from the co_contact table
                 co_contact.cont_title,
                 co_contact.cont_email
          FROM company
          LEFT JOIN co_contact
            ON company.company_id = co_contact.company_id
          WHERE comp_county = 'BERNALILLO'
          ORDER BY company.comp_name, co_contact.cont_rank";

Try changing the query. What result do you get now?

Edited by Ch0cu3r

@ch0cu3r - Thank you so much for your patience and explanations.  The code is indeed working, and when I changed the queries to select only the three fields from both co_contact and br_contact tables, and did a little more formatting of the output, it looks like this: http://www.nmlta.org/NewMemDir/bern_psycho-test2.php

 

There is one caveat, though - there is a Warning after the first company listing, I assume that is because there is no branch associated with the first company.  Is there any way to get rid of that warning? Here is the complete working code now:


// Retrieve ALL the "company" specific data (including contacts)
$query = "SELECT company.*,
			co_contact.cont_name,
			co_contact.cont_title,
			co_contact.cont_email
          FROM company
          LEFT JOIN co_contact
            ON company.company_id = co_contact.company_id
          WHERE comp_county = 'BERNALILLO'
          ORDER BY company.comp_name, co_contact.cont_rank";

$result = $mysqli->query($query) or die($mysqli->error.__LINE__);

// Build the $company_array
$company_array = array();
while($row = $result->fetch_assoc())
{
    if(!isset($company_array[$row['company_id']]))
    {
        //Add the company specific data here
        $company_array[$row['company_id']] = array(
            'name'    => $row['comp_name'],
            'street' => $row['comp_street'],
            'csz'	=>	$row['comp_csz'],
            'phone'   => $row['comp_ph'],
            'fax'     => $row['comp_fx'],
            'web'     => $row['comp_web'],
            'email'   => $row['comp_email'],
            //'branches'		=>	array(),
            //'br_contacts'	=>	array()
            );
    }

    //Add the company contact info here
    $company_array[$row['company_id']]['co_contacts'][] = array(
        'name' => $row['cont_name'],
        'title' => $row['cont_title'],
        'email' => $row['cont_email']
    );
}

//Run query to get branch info - for ALL companies
$query = "SELECT branch.*, br_contact.cont_name, br_contact.cont_title, br_contact.cont_email
          FROM branch
          JOIN company ON branch.company_id = company.company_id
          LEFT JOIN br_contact
            ON branch.branch_id = br_contact.branch_id
          WHERE company.comp_county = 'BERNALILLO'
          ORDER BY company.comp_name, branch.br_street, br_contact.cont_rank";

$result = $mysqli->query($query) or die($mysqli->error.__LINE__);

//Add branch (and branch contacts) results to $company_array
while($row = $result->fetch_assoc())
{
    $compID = $row['company_id'];
    $branchID = $row['branch_id'];
    if(!isset($company_array[$compID]['branches'][$row['branch_id']]))
    {
        $company_array[$compID]['branches'][$branchID] = array(
            'branch_name' => $row['branch_name'],
            'street'     => $row['br_street'],
            'csz'		=>	$row['br_csz'],
            'phone'       => $row['br_ph'],
            'fax'         => $row['br_fx']
        );
    }

    $company_array[$compID]['branches'][$branchID]['br_contacts'][] = array(
        'name' => $row['cont_name'],
        'title' => $row['cont_title'],
        'email' => $row['cont_email']
    );
}

// Start building the table for showing results
echo "<table border='1' cellpadding='10' cellspacing='0' bgcolor='#f0f0f0' style='margin-left:100px; margin-bottom:20px'>";

// Begin the "foreach" loop for rows in the $company_array

foreach($company_array as $company)
{
    echo "<tr><td>\n";
    echo "<b>{$company['name']}</b><br>\n";
    echo "{$company['street']}<br>\n";
    echo "{$company['csz']}<br>\n";
    echo "{$company['phone']} Fax: {$company['fax']}<br>\n";
    if(!empty($company['web'])) {
    echo "{$company['web']}<br>\n";}
    if(!empty($company['email'])) {
	echo "Email: <a href='mailto:{$company['email']}'>{$company['email']}</a><br><br>\n";}
    
    foreach($company['co_contacts'] as $co_contact)
    {
        echo "&nbsp&nbsp&nbsp <b>{$co_contact['name']}</b>, {$co_contact['title']}<br>\n";
     	if(!empty($co_contact['email'])) {
		echo "&nbsp&nbsp&nbsp Email: <a href='mailto:{$co_contact['email']}'>{$co_contact['email']}</a><br>\n";}
		echo "<br>";
	}
    
    foreach($company['branches'] as $branch)
    {
        echo "&nbsp&nbsp&nbsp <b>{$branch['branch_name']}</b><br>\n";
        echo "&nbsp&nbsp&nbsp {$branch['street']}<br>\n";
        echo "&nbsp&nbsp&nbsp {$branch['csz']}<br>\n";
        echo "&nbsp&nbsp&nbsp {$branch['phone']} Fax: {$branch['fax']}><br>\n";
        if(!empty($branch['email'])) {
		echo "&nbsp&nbsp&nbsp Email: <a href='mailto:{$branch['email']}'>{$branch['email']}</a><br>\n";}
		echo "<br>";
        foreach($branch['br_contacts'] as $br_contact)
        {
            if(!empty($br_contact['name'])) {			
            echo "&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp <b>{$br_contact['name']}</b>, {$br_contact['title']}<br>\n";}
            if(!empty($br_contact['email'])) {
			echo "&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp Email: <a href='mailto:{$br_contact['email']}'>{$br_contact['email']}</a><br>\n";}
			echo "<br>";
        }
    }
    echo "</td></tr>\n";
}
echo "</table>";


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.