Not able to retrieve a single value from php array -


we have stored procedure in mssql returns 2 values:

agent | tickets int   | int 

we connecting database server , calling sp pdo this:

<?php  //declare hostname variable $hostname = 'servername';  try { $conn = new pdo("sqlsrv:server=$hostname;database=dbnamee"); $conn->setattribute(pdo::attr_errmode, pdo::errmode_exception); $agent = 249; $stmt = $conn->prepare("{call proc_getactiveticketsforagent (:agent)}"); $stmt->bindparam(":agent",$agent, pdo::param_str); $stmt->execute();  $results = array(); { $results []= $stmt->fetchall(); } while ($stmt->nextrowset());  echo '<pre>'; print_r($results);echo "\n"; // record sets echo '</pre>'; ?> 

this outputs full array (as test).

what trying returning value of tickets (for example; 6, current number of tickets on agent 249), , can using:

$results = $stmt->fetch(pdo::fetch_obj); print($results->tickets); 

when go our index site, , use include() function, can output whole array (this part of code):

<!doctype html> <html> <head> <title>sitetitle</title> <meta charset="utf-8"> </head> <body> <?php include('phpfile.php');  ?> <p> <?php echo '<pre>'; print_r($results);echo "\n"; // record sets echo '</pre>'; ?> </p> </body> </html> 

but when try use same function earlier:

print($results->tickets); 

i "500 - internal server error"

can see going wrong? starting go bald pulling hair out.

thanks.

use after execute statement:

$results = $stmt->fetchall() 

then loop through results:

foreach($results $row){     echo $row['agent']. ": ". $row['tickets']; } 

Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -