Last active
September 17, 2015 15:21
-
-
Save coquer/9df905f3b09f4b782c9b to your computer and use it in GitHub Desktop.
Mixing multidimensional array into one.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function getAllDataForACompany($company_reg_name){ | |
$data = []; | |
$connection = new mysqli( self::DB_HOST, self::DB_USER, self::DB_PASSWORD, self::DB_NAME ); | |
if ( $connection ) { | |
if ( $result = $connection->query( "SELECT * FROM APITester WHERE registerd_company_name = '$company_reg_name'", MYSQLI_USE_RESULT ) ) { | |
$data['registerd_company_name'] = $company_reg_name; | |
$registration_numbers = []; | |
$catgeories = []; | |
$company_classes = []; | |
while ( $row = $result->fetch_assoc() ) { | |
if(!in_array($data, $row)){ | |
$data['town'] = $row[ 'town' ]; | |
} | |
if(!in_array($registration_numbers, $row)){ | |
array_push($registration_numbers, $row['registration_number']); | |
} | |
if(!in_array($company_classes, $row)){ | |
array_push($company_classes, $row['company_class']); | |
} | |
if(!in_array($catgeories, $row)){ | |
array_push($catgeories, $row['catgeory']); | |
} | |
} | |
$data['registation_nembers'] = array_unique($registration_numbers); | |
$data['company_classes'] = array_unique($company_classes); | |
$data['catgeories'] = array_unique($catgeories); | |
return $data; | |
} else { | |
return array( 'error' => 'nothing_to_see_here', 'rerun' => true, 'company_reg_name' => $company_reg_name ); | |
} | |
} else { | |
return array( 'error', 'no_possible_to_connect', 'conn' => false ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment