Solved

How do you display values returned from call to stored procedure in php using odbc?

Posted on 2010-09-21
2
308 Views
Last Modified: 2013-12-12
Apparently php handles results of a normal select query and a call to a stored procedure differently as I can't seem to get to the data returned.

My code:

$sql='CALL GETSTORES('.$a.')';
$result = odbc_exec($con, $sql);
while (odbc_fetch_row($result))
{
  $num_stores++;
}

$num_stores--;
echo"numstores:".$num_stores."<br />";

//echo odbc_result($result,'ABNAME');     at least this gives the store name

while (odbc_fetch_row($result))
{
   $storen=odbc_result($result,"abname");
   $storenum=odbc_result($result,"store");
   echo"store:".$storen." store#:".$storenum."<br />";
}

Open in new window


The commented out line is as close as I have gotten to "seeing" the data.  odbc_fetch_row apparently does not work as nothing happens when the code runs.

I can loop and increment $num_stores to the correct number of records returned (4). odbc_num_rows returned -1 so I had to loop to count the records returned.

Any suggestions on how I can loop through the returned records?  The stored procedure returns the store name as well as store number.
0
Comment
Question by:Richardetal
2 Comments
 

Author Comment

by:Richardetal
Comment Utility
My stored procedure resides on our iSeries box V5r4
0
 
LVL 42

Accepted Solution

by:
Chris Stanyon earned 125 total points
Comment Utility
In you code - lines 3-6 you are looping through the recordset until there are no more records to loop through. When you come to loop through them again in lines 13-18 there are no more records - you've already looped through them.

You need to reset you internal record counter, by telling odbc_fetch_row to start at record 1.

odbc_fetch_row($result, 1);

You can read more about it here:

http://php.net/manual/en/function.odbc-fetch-row.php
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now