Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Behaviour of assigning mysql_fetch_array to another array

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Behaviour of assigning mysql_fetch_array to another array

Postby Nunners » Thu Sep 25, 2003 12:22 am

I have the following line in my code:

Code: Select all
$easting[$row_num]=$accommodation["EASTING"];
echo("Easting test: ".$accommodation["EASTING"]." and ".$easting[$row_num]);


$accommodation is a mysql_fetch_array, with EASTING being a field within it.
$row_num is increasing each time the mysql_fetch_array passes through, using ++;

The output I get is as follows:
Easting test: 369234 and 3


Now am I completely loosing it, or should the two numbers not be the same?
It would seem when assigning the value to the array $easting, it only takes the first digit. Is this a fault, a problem with my code, or just one of those things?!?

Many thanks
Nunners
Nunners
New php-forum User
New php-forum User
 
Posts: 3
Joined: Fri Jan 10, 2003 8:20 am
Location: Worcester, UK

Postby DigitalRice » Thu Sep 25, 2003 8:00 am

when using mysql_fetch_array(your_result_query)

the return result will be number index and also associate fields. to get rid of the index field when the query return, try one of this.
Code: Select all
mysql_fetch_array(your_result_query, MYSQL_ASSOC)
or
mysql_fetch_assoc(your_result_query)


this only return the associate field as you wanted.
DigitalRice
New php-forum User
New php-forum User
 
Posts: 29
Joined: Fri Jun 27, 2003 10:05 pm

Postby Nunners » Thu Sep 25, 2003 8:05 am

Thanks for the suggestion.

I've actually solved the problem.

It was all down to the variable easting being defined previously in the script!
Nunners
New php-forum User
New php-forum User
 
Posts: 3
Joined: Fri Jan 10, 2003 8:20 am
Location: Worcester, UK


Return to PHP coding => General

Who is online

Users browsing this forum: Google [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron