Solved

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

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How would I do a website like this? 5 57
Google Maps API and PHP 25 30
PHP curl issue VERBOSE output 18 42
What does != "" mean in programming 8 30
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…

773 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