Hi all

I'm having a strange array problem. I'm pulling variables from a database and putting the values in arrays. One set of values are pure numbers. This array works fine. My second set of values are a mixture of numbers and letters. This second array just returns values of 0.

Example of the "$code" values:

D045RND
D055RND

Code:

while($row = mysql_fetch_row($connect->result))
{
	$price[] += $row[0];
	$code[] += $row[1];
}

For instance, when I echo $code[0] it comes up as 0. The same goes for every iteration of $code[] ($code[1], $code[2], $code[3] etc).

Any help would be greatly appreciated ;)

Recommended Answers

All 4 Replies

See the contents of your variable with

print_r($row);

This prints out all the values in an array

See the contents of your variable with

print_r($row);

This prints out all the values in an array

Hi samarudge

I've checked my $row[1] variable using a while loop and all the values from the database are coming through. For some reason it just won't work with an array. It's really confusing because I have the first array working perfectly.

Your problem stems from that the fact that php will try and convert anything that is not a number into a number when trying to add it (the +=). Most of the time, it just turns into a nice 0. Remove the plus sign.

commented: Saved me from hours of frustration. Thanks ;) +2

Your problem stems from that the fact that php will try and convert anything that is not a number into a number when trying to add it (the +=). Most of the time, it just turns into a nice 0. Remove the plus sign.

LOL...I could kick myself right now. This is one of those situations where a simple character messes you around completely. Thanks a lot kkeith29.

Problem Solved!!!!!!!!!

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.