SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict MikesBarto2002's Avatar
    Join Date
    May 2006
    Location
    New York City
    Posts
    317
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question 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:

    Screen shot 2011-10-06 at 12.52.57 PM.jpg

    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:
    PHP 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:
    PHP Code:
    $address = new organization_info;
    $letsseeit $address->Get_organization_address();
    print_r($letsseeit); 
    Any suggestions?
    James Web Development | New York, NY
    Design, Develop, Deliver

  2. #2
    SitePoint Enthusiast
    Join Date
    Oct 2011
    Posts
    47
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  3. #3
    SitePoint Addict MikesBarto2002's Avatar
    Join Date
    May 2006
    Location
    New York City
    Posts
    317
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Worked perfectly! Thanks for your help!
    James Web Development | New York, NY
    Design, Develop, Deliver

  4. #4
    SitePoint Enthusiast
    Join Date
    Oct 2011
    Posts
    47
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by MikesBarto2002 View Post
    Worked perfectly! Thanks for your help!
    Glad to help


Bookmarks

Posting Permissions

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