?
Solved

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

Posted on 2010-09-21
2
Medium Priority
?
318 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 45

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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses
Course of the Month16 days, 7 hours left to enroll

850 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