Class not pulling up database information

The following code does not result in any errors, yet it is still not pulling up the address information that I need. I have attached a screen shot to show what I mean:

If you look at the top left corner, you can see that the function Get_organization_name is working, but the address is supposed to be under it. I am just trying to print the array of the function Get_organization_address, but it’s not working.

Here is the code:


class organization_info {

	var $general;
	
	function Get_organization_name() {
		global $mysqli;
		$query = "SELECT value FROM general WHERE setting='organization_name'";
		$result = $mysqli->query($query); 	
		if ($result) {
			while ($row = $result->fetch_object()){
        		$this->general = $row->value;
			}
			$result->close();
		}
		return $this->general;
	}
	
	function Get_organization_address() {
		global $mysqli;
		$this->general = array();
		$query = "SELECT value FROM general WHERE setting='address_1';";
		$query .= "SELECT value FROM general WHERE setting='address_2';";
		$query .= "SELECT value FROM general WHERE setting='city';";
		$query .= "SELECT value FROM general WHERE setting='state_region';";
		$query .= "SELECT value FROM general WHERE setting='zip_code';";
		$query .= "SELECT value FROM general WHERE setting='country'";
		if ($mysqli->multi_query($query)) {
    		do {
        		if (isset($result) && $result = $mysqli->store_result()) {
            		while ($row = $result->fetch_row()) {
                		$this->general[] = $row[0];
            		}
            		$result->free();
        		}

    		} while ($mysqli->next_result());
		}
		if (isset($result)) {
			$result->close();
		}
		return $this->general;
	}
	
	function Get_organization_mailing_address() {
		global $mysqli;
		$this->general = array();
		$query = "SELECT value FROM general WHERE setting='mailing_address_1';";
		$query .= "SELECT value FROM general WHERE setting='mailing_address_2';";
		$query .= "SELECT value FROM general WHERE setting='mailing_city';";
		$query .= "SELECT value FROM general WHERE setting='mailing_state_region';";
		$query .= "SELECT value FROM general WHERE setting='mailing_zip_code';";
		$query .= "SELECT value FROM general WHERE setting='mailing_country'";
		if ($mysqli->multi_query($query)) {
    		do {
        		if (isset($result) && $result = $mysqli->store_result()) {
            		while ($row = $result->fetch_row()) {
                		$this->general[] = $row[0];
            		}
            		$result->free();
        		}

    		} while ($mysqli->next_result());
		}
		if (isset($result)) {
			$result->close();
		}
		return $this->general;
	}

}

And I am using this code to print the array:


$address = new organization_info;
$letsseeit = $address->Get_organization_address();
print_r($letsseeit);

Any suggestions?

Look at this if statement:

if (isset($result) && $result = $mysqli->store_result())

You are not defining $result prior to the do-while loop, so when that if statement is triggered, its gonna do isset($result) and it will return false; therefore, the code inside the if block will not be executed.

Make your code look similar to Example #1 at:
http://php.net/manual/en/mysqli.multi-query.php

Worked perfectly! Thanks for your help!

Glad to help :slight_smile: