cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
801
Views
0
Helpful
0
Comments
cdnadmin
Level 11
Level 11
This document was generated from CDN thread

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

$response for 0 users
stdClass Object (  => stdClass Object ( ) )

$response for 1 user
stdClass Object (  => stdClass Object (  => stdClass Object (  => Marc  => Maxim ) ) )

$response for 2 users
stdClass Object (  => stdClass Object (  => Array ( [0] => stdClass Object (  => Richard  => Mann ) [1] => stdClass Object (  => Marc  => Maxim ) ) ) )

These all can be solved by checking count value and building IF tree. I'm not sure if your foreach loop can be improved in a simpler way.

Subject: RE: PHP, executeSQLQuery
Replied by: Andrey Visotskiy on 01-02-2011 07:39:26 AM
giv me all php code. i`m look...

Subject: RE: PHP, executeSQLQuery
Replied by: Mark Hyperion on 03-02-2011 05:09:02 AM
here we go:

<?php

$count = 0;
$params = array('sql' => 'SELECT firstname,lastname FROM enduser WHERE lastname LIKE "a%"');

$client = new SoapClient("AXLAPI.wsdl",
        array('trace'=>true,
        'exceptions'=>true,
        'location'=>"https://10.1.1.1:8443/axl",
        'login'=>'AXL_USER',
        'password'=>'password',
        ));
         
$response = $client->executeSQLQuery($params);
$count = count($response->return->row);
echo ("Users found: ".$count."<br>"."<br>");

foreach($response->return->row as $enduser) :
        echo $enduser->firstname." ".$enduser->lastname."<br>";
endforeach;

print_r($response);

?>
Getting Started

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:

Quick Links