0

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 ;)

3
Contributors
4
Replies
5
Views
8 Years
Discussion Span
Last Post by Venom Rush
0

See the contents of your variable with

print_r($row);

This prints out all the values in an array

0

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.

1

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.

Votes + Comments
Saved me from hours of frustration. Thanks ;)
0

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!!!!!!!!!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.