0

I'm trying to create an API and I need to put multiple queries into my JSON ouput, the issue is everything is returned as an object of class stdClass... here is my code:

$querystr = "SELECT  entry_id AS id FROM {$wpdb->prefix}connections_term_relationships WHERE term_taxonomy_id = '{$_GET['catID']}'"; 
    $cID = $wpdb->get_results($querystr);


    $dirCount=count($cID);
    $arrayCategory= array();
    $androidArray = array();

    if($dirCount > 0){
        foreach($cID as $company){
            $querycInfo = "SELECT id, organization, contact_first_name, contact_last_name, bio  FROM {$wpdb->prefix}connections WHERE id = '{$company->id}'"; 
            $companyInfo = $wpdb->get_row($querycInfo);
            $queryAddress = "SELECT  line_1, line_2, line_3, state, zipcode FROM {$wpdb->prefix}connections_address WHERE entry_id = '{$company->id}'"; 
            $address = $wpdb->get_row($queryAddress);
            $queryEmail = "SELECT  address  FROM {$wpdb->prefix}connections_email WHERE entry_id = '{$company->id}' AND type = 'work'"; 
            $email = $wpdb->get_row($queryEmail);
            $queryWebsite = "SELECT  title, url  FROM {$wpdb->prefix}connections_link WHERE entry_id = '{$company->id}' AND type = 'website'"; 
            $website = $wpdb->get_row($queryWebsite);
            $queryPhone = "SELECT number FROM {$wpdb->prefix}connections_phone WHERE entry_id = '{$company->id}' AND type = 'workphone'"; 
            $phone = $wpdb->get_row($queryPhone);


        $arrayCategory[]= $companyInfo;


        }
    }else{
        $arrayCategory[0]=array('organization'=>'No Company Found Within This Category');
    }

    $androidArray = array('companies'=>$arrayCategory);
echo json_encode($androidArray);
}

I need $arrayCategory to hold more then just $companyInfo, I need it to hold the other variables as well. This is being built for WordPress. Thanks in advance!

4

1 回答 1

0

我最终只是用更有意义的方式格式化了我的 SQL 查询:

$querycInfo = "SELECT main.id, organization, contact_first_name, contact_last_name, bio, number  FROM {$wpdb->prefix}connections main
            JOIN {$wpdb->prefix}connections_phone phone ON phone.entry_id = main.id AND main.id = '{$company->id}'"; 

这解决了这个问题。

于 2013-05-14T17:54:47.497 回答