Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1

Thread: Coding Problem

  1. #1
    SJL
    SJL is offline
    New to the CF scene
    Join Date
    May 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Coding Problem

    I had a programmer write a search query against my MySql db to use as a member directory. The code I am interested in is below. This section goes looking for a member company [company1] and then displays the companies in order. The problem is that there is another field called [company2] that contains the names of individual plants of each company. In my mind, the $company_name should check fields [company1] and [company2] so that the individual plants of those members who have multiple locations are picked up. The results now just show one entity for each member with all employees listed below that entity. I would like to show the multiple plant listings as well. I'm not really sure whether the coding is php or MySql since I'm not a programmer. I did edit the line $company_name = to $company_name = $row[company1] AND $row[company2]; but that did not work for me when the results displayed. It just put a blank line in and I'm not sure if the AND is appropriate in the statement. Any help would be appreciated!

    Code:
    while($row = $q->fetchrow()){
    	//this is where we are rolling through the results.
    
    	//find out if this is a new company, or a new person in the same company
    	$company_name = $row[company1];  //works
                                    
    	if($company_name == ""){
    		//the company name is blank so skip it...
    	}
    	else{
    		if($company_name != $lastloopcompanyname){
    		//this is the first listing in the company
    			echo("</br></br><h3>$company_name</h3>");
                            echo("$row[address1]</br>");
    			if($row[address2]){
    				echo("$row[address2]</br>");
    			}
    			echo("$row[city], $row[state] $row[zip] $row[country]</br>");
    			if($row[phone]){
    				echo("<strong>Phone:</strong> $row[phone]</br>");
    			}
    			if($row[fax]){
    				echo("<strong>Fax:</strong> $row[fax]</br>");
    			}
    			echo("</br>$row[fname] $row[lname]");
    			if($row[title]){
    				echo" - $row[title]";
    			}
    			echo "</br>";
    			if($row[emailaddress]){
    				echo("<strong>Email:</strong> $row[emailaddress]</br>");
    			}
    		}
    		else{
    		//this is not the first listing in the company
                            echo("</br>$row[fname] $row[lname]");
    			if($row[title]){
    				echo" - $row[title]";
    			}
    			echo "</br>";
    			if($row[emailaddress]){
    				echo("<strong>Email:</strong> $row[emailaddress]</br>");
    			}
    		}
    	}
    
    
    	$lastloopcompanyname = $company_name; //this sets the company name to the last loop company name for the next while
    }
    Last edited by FishMonger; 05-15-2014 at 07:05 PM.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •