Fetching numbers from a database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
toppac
Forum Commoner
Posts: 29
Joined: Fri Jun 14, 2002 10:44 am

Fetching numbers from a database

Post by toppac »

I am trying to fetch a number from a databse. I have a field that is set to either 1 or 0. I can set the values fine but when I try pull the values back I get null. My code looks like this

Code: Select all

OCIFetchInto($statement, $rc, OCI_ASSOC);
$prodgroup = $rcї'PRODGROUP'];
$groupname = $rcї'GROUPNAME'];
$site = $rcї'SITE'];
$infomerical = $rcї'INFOMERCIAL'];
echo $infomercial." test";
the echo doesnt print anything. There are values in the DB for the field 'INFOMERCIAL', but it wil not get them. Any ideas?
calebsg
Forum Commoner
Posts: 28
Joined: Tue Jun 18, 2002 10:41 am

Post by calebsg »

Could all your values be equal to 0, hence the consistent return of a null value?
Last edited by calebsg on Tue Aug 13, 2002 2:36 pm, edited 1 time in total.
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Ummm.......

Post by BDKR »

Hi,

As a way of testing, did you try to echo the info right out of the returned array.
Something like....

Code: Select all

OCIFetchInto($statement, $rc, OCI_ASSOC);
$prodgroup = $rcї'PRODGROUP'];
$groupname = $rcї'GROUPNAME'];
$site = $rcї'SITE'];
$infomerical = $rcї'INFOMERCIAL'];

# Now echo for testing
echo $rcї'INFOMERCIAL']."test";

# The old way
# echo $infomercial." test";
I'm assuming this is Oracle. Before this code, are you using OCIparse()? If so, are you testing that $statement doesn't equal false?

Perhaps something like:

Code: Select all

if( ($statement = OCIparse($conn, $query)) != false )
    { /* Insert your code here */ }
Now eventhought this may look good, and the manual says OCIparse() will return false on failure, there are those that say it allways returns true. I don't know one way or the other, but the nay sayers suggest using OCIerror() as well. You may wish to check this out in the manual.

Remember, the manual is your friend. (A lot nicer than RTFM)

And lastly, why take the extra step of assigning to vars each element of the associative array? I agree that there are at times good reasons for this; I just thought I'd ask.

later on and hope that helps,
BDKR (TRC)
toppac
Forum Commoner
Posts: 29
Joined: Fri Jun 14, 2002 10:44 am

Post by toppac »

Yes some of the values are equal to 0, but some are also equal to 1, which is still returning null. The database field is supposed to hold 1 or Null. When I check the database it has a value in it, but that value will not get returned.

The variables are actually global vars, i have to use them in other functions. I just did not want to type out $_POST[] each time :wink:
toppac
Forum Commoner
Posts: 29
Joined: Fri Jun 14, 2002 10:44 am

Post by toppac »

Fixed it. It was a damn typo. I had $infomerical instead of $infomercial. Sorry to waste everyones time, gonna go pull my hair out some more. :cry:
Post Reply