Created by: Mark Hyperion on 12-01-2011 11:50:32 AM Hello, I have probably a simple problem generating output out of SQL query using PHP. SQL query works fine but I'm not sure how to output list of elements found. Questions: - How to find out a number of found users - How to echo the list of found users (number of users can be 0, 1 to more) Here is the example code: <?php
$params = array('sql' => 'SELECT firstname, lastname FROM enduser"');
$client = new SoapClient("AXLAPI.wsdl", array('trace'=>true, 'exceptions'=>true, 'location'=>"https://10.88.131.133:8443/axl", 'login'=>'Administrator', 'password'=>'cisco!123', )); $response = $client->executeSQLQuery($params); print_r($response); // wished echo list of sql query selected users firstname, lastname ?> ******************** Example of of print_r($response) when found 0 users: stdClass Object ( => stdClass Object ( ) ) 1 user: stdClass Object ( => stdClass Object ( => stdClass Object ( => Max => Spencer ) ) )
2 users: stdClass Object ( => stdClass Object ( => Array ( [0] => stdClass Object ( => Richard => Man ) [1] => stdClass Object ( => John => Doe ) ) ) )
Thank you for your help. regarads, Mark
Subject: RE: PHP, executeSQLQuery Replied by: Andrey Visotskiy on 01-02-2011 03:08:07 AM echo count($response->return->row) - count of response elements ( you users )
and second question
foreach($response->return->row as $enduser) :
echo $enduser->firstname." ".$enduser->lastname;
endforeach;
enjoy
Subject: RE: PHP, executeSQLQuery Replied by: Mark Hyperion on 01-02-2011 05:55:04 AM Thank you, apparently i have used wrong arguments in a count definition "count($response->return->row)" versus "count((array)$response->return->row)"
Unfortunately the foreach loop doesn't return values if the number of users is 1 and returns Invalid argument if value is 0
Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: