?
Solved

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

Posted on 2010-09-21
2
Medium Priority
?
313 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Author Comment

by:Richardetal
ID: 33726230
My stored procedure resides on our iSeries box V5r4
0
 
LVL 43

Accepted Solution

by:
Chris Stanyon earned 500 total points
ID: 33727041
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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.
Suggested Courses

741 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