Solved

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

Posted on 2010-09-21
2
312 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 125 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

Technology Partners: 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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
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.

726 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