This i sdriving me nuts and I know there should be an easy answer. Here is the php

$sql4 = 'select tranamt, tracct
          from bd.bdptran
          where bd.bdptran.trnum = 105 ';

$result4 = db2_exec($conn, $sql4);

while($row4 = db2_fetch_array($result4)) {
    echo $row4[0] ."<br />";
    echo $row4[1] ."<br />";
}

I get the results i want and it echo's like this
56.00
1A1
67.00
1A11A
45.00
1A10

The numbers are an array and the letter/numbers are another array.
My question is, how do i use the indivdual fields; meaning, say I just wanted to echo 56.00. Or 1A11A. How would I do that? I tried using foreach with an index number, but if I use the index[0] I will get a result of
5
1
6
1
4
1

Thanks guys.

Recommended Answers

All 2 Replies

You could use db2_fetch_row() and db2_result(), check the first example in the documentation:

But instead of the loop, that moves the internal pointer to the next row, you can use an IF statement and get only the first row:

if(db2_fetch_row($result4))
{
    $number   = db2_result($result4, 0);
    $alphanum = db2_result($result4, 1);
}

# moving to the second row
db2_next_result($result4);

# repeat the previous IF statement

THANK YOU very much!!
That worked perfect.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.