Not able to retrieve a single value from php array

We have a Stored Procedure in MSSQL that returns two values:

Agent | Tickets int | int

We are successfully connecting to the database server and calling the SP with pdo like 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(); do { $results []= $stmt->fetchAll(); } while ($stmt->nextRowset()); echo '<pre>'; print_r($results);echo "\n"; // all record sets echo '</pre>'; ?>

This outputs the full array (as a test).

What I am trying to do is returning the value of Tickets (for example; 6, which is the current number of tickets on agent 249), and I can do this by using:

$results = $stmt->fetch(PDO::FETCH_OBJ); print($results->Tickets);

When I go to our index site, and use the include() function, I can output the whole array (this is just a part of the 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"; // all record sets echo '</pre>'; ?> </p> </body> </html>

But when I try to use the same function as earlier:

print($results->Tickets);

I get "500 - internal server error"

Can anyone see where I am going wrong? I am starting to go bald from pulling my hair out.

Thanks.

--------------Solutions-------------

Use something like this after your execute statement:

$results = $stmt->fetchAll()

Then to loop through the results:

foreach($results as $row){
echo $row['Agent']. ": ". $row['Tickets'];
}

Category:php Time:2018-12-05 Views:1

Related post

  • how to get single value from php array 2010-12-08

    Example print_r($myarray) Array ( [0] => Array ( [id] => 6578765 [name] => John Smith [first_name] => John [last_name] => Smith [link] => http://www.domain.com [gender] => male [email] => [email protected] [timezone] => 8 [u

  • Not able to display all the values from database 2011-09-15

    i am new to sqlite , i cant able to display all the values but can display first value, but i can display all the values using TOAST --------------Solutions------------- you can see the whole data using Loop, passing cursor index can see the example

  • PHP - Pulling single value from multidimensional array 2010-02-05

    this is probably quite simple but I could do with some help. I am trying to create a small PHP function that will display a single value form a multidimensional array when the user used two dropdown boxes to select the row and column of the array. So

  • Retrieving MYSQL Join values from PHP 2009-11-03

    I have two or more tables which hold values under the same column name. Now when I join these two tables the column names stay the same. When retrieving these values in PHP ($row['name']) I encounter problems since the column 'name' is used twice. Ar

  • How do I retrieve the first value from an array? 2011-12-24

    I have a call to a YouTube XML sheet that works perfectly fine. However, I am having trouble setting a value from one of the arrays. I want the first value from "songID" to be set as "first". I've tried doing this: var first = songID[0] but it only m

  • jQuery.each how to get values from PHP array 2011-06-17

    I have following array return from server side: [json] => Array ( [0] => {"sEcho":1,"iTotalRecords":"4","iTotalDisplayRecords":"4","bid":"22","aaData":[[1,"Monetary Bid name","12","4.00","6.00","-",".25\/50","-"],[2,"Monetary Bid name","14","5.

  • Remove Values from PHP Array if Present 2011-09-19

    I have the following PHP array: Array ( [0] => 750 [1] => 563 [2] => 605 [3] => 598 [4] => 593 ) I need to perform the following action on the array using PHP: Search the array for a value (the value will be in a variable; let's call i

  • Not able to get the selected values from Drop down using Jquery 2011-06-16

    i'm trying to add new field to existing gsp page which was written by some other guy. <g:select name="clientId" multiple = "yes" size = "4" from="${com.mycompany.fleet.partymodel.roles.ClientRole.list()}" class = "filter_combo" optionKey="id" /

  • jQuery not able to retrieve placeholder attribute value? 2010-11-21

    Is there a jQuery way for me to retrieve the placeholder attribute of a form input element? I've tried the obvious: alert($('form_input_element').attr('placeholder')); but it returns undefined in both firefox and chrome for some reason! All other att

  • not able to split the number value from the string 2016-12-19

    I'm creating a Udf function for an area conversion program in java. I have the following data: 230Sq.feet 110Sq.yards 8Acres 123Sq.Ft I want to split the above data like this: 230 Sq.feet 990 Sq.feet 344 Sq.feet 123 Sq.feet I tried the following code

  • Not able to update PostgreSQL database table from PHP 2012-01-27

    The following query works in PostgreSQL but when I run it through php, it doesn't update. Any idea what I might be doing wrong? It's my first time with PostgreSQL. <?php $connection = pg_connect("host=localhost port=5432 dbname=mydb user=myuser pa

  • Getting Values from PHP Array 2011-07-31

    I have the following array: $array = array(1=>'one', 2=>'two', 3=>'three'); I know it's possible to use array_search(); to return "1" when searching for "one", but how do I return "one" when searching for "1"? I've tried $array[1], but this

  • How to remove duplicate values from PHP array based on part of string 2011-12-07

    I have a text file in the form of [email protected]\n. I put the data into an array with explode(). How can I remove duplicate lines (values) based on Phone only? I want to avoid [email protected] [email protected] I want to make this unique based on the Phone

  • accessing values from php array 2012-02-10

    I have been having an issue getting values out of an array that is formatted like so: array( [key]=>array( [0]=>value [1]=>value [2]=>value) [key]=>array( [0]=>value [1]=>value)) I am using a queue to run through each key as the

  • Extract a row by value from php array 2016-02-27

    This is my array: Array ( [0] => Array ( [SocketID] => 1 [SocketName] => Name [SocketDecimal] => 0 [SocketHex] => 00 [SocketAtt] => 1 [Category] => 1 [Value] => 100 [Procentage] => 0 ) [1] => Array ( [SocketID] => 2 [Socke

  • Exctract values from php array 2011-09-06

    I have an array like this (this is actually a WordPress category list array): Array ( [0] => stdClass Object ( [term_id] => 4 ) [1] => stdClass Object ( [term_id] => 6 ) ) Is there a way to exctract "term_id" values and assign it to $term

  • min and max value from php array 2012-01-16

    $array = [0,1,2,3,4,5,6]; $min = min($array); $max= max($array); I want min as 1 and max as 6 i don't want to consider 0 as min with php array. --------------Solutions------------- Use array_filter to filter the zero out of the array $a = array(0,1,2

  • not able to retrieve old session variable values in php 2010-11-18

    Hi i am new to PHP.I am having "item.php" page and "cart.php" page. In item.php 3 checkboxes are available. if i click on one checkbox from item.php the value is sent to to cart.php page. however if i go back and select another checkbox the old value

  • How to remove values from an array in PHP? 2009-08-17

    Is there a PHP function to remove certain array elements from an array? E.g., I have an array (A) with values and another array (B) from which a need to remove values. Want to remove the values in array A from array B? --------------Solutions--------

Copyright (C) pcaskme.com, All Rights Reserved.

processed in 5.476 (s). 15 q(s)