By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,719 Members | 1,278 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,719 IT Pros & Developers. It's quick & easy.

mysql_fetch_array... interesting

P: n/a
hi all

this is probably another simple one, but the web doesnt seem to have an
answer that I can find.
Veeeery simple code. each row has 10 columns.

require('db.php');
$query = "SELECT * FROM mytable";
$result = mysql_query($query);
$numrows = mysql_num_rows($result);

for($x=0; $x<$numrows; $x++)
$row_arrays[$x] = mysql_fetch_array($result);

//test row 1
foreach($row_arrays[1] as $count)
print "$count<br>";

result for each print is the column number (0-9) and each id(0,a,1,b,2,c
etc). But if I use mysql_fetch_array($result, 'MSQL_ASSOC') as the docs
say, I get the 'The result type should be either MYSQL_NUM, MYSQL_ASSOC or
MYSQL_BOTH' error. No quotes, additional error about undefined constant. I
figure using this would get the array including the id only and not include
the number. Perhaps its the wrong assumption?

thanks
Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Theo wrote:
hi all

this is probably another simple one, but the web doesnt seem to have an
answer that I can find.
Veeeery simple code. each row has 10 columns.

require('db.php');
$query = "SELECT * FROM mytable";
$result = mysql_query($query);
$numrows = mysql_num_rows($result);

for($x=0; $x<$numrows; $x++)
$row_arrays[$x] = mysql_fetch_array($result);

//test row 1
foreach($row_arrays[1] as $count)
print "$count<br>";

result for each print is the column number (0-9) and each id(0,a,1,b,2,c
etc). But if I use mysql_fetch_array($result, 'MSQL_ASSOC') as the docs
say, I get the 'The result type should be either MYSQL_NUM, MYSQL_ASSOC or
MYSQL_BOTH' error. No quotes, additional error about undefined constant. I
figure using this would get the array including the id only and not include
the number. Perhaps its the wrong assumption?

thanks

Hi,

the second parameter of mysql_fetch_array function must be an INTEGER.
MYSQL_BOTH, MYSQL_NUM and MYSQL_ASSOC are contants and have to be
specified without single or double quote.

bye
Jul 17 '05 #2

P: n/a
Gabriele Farina *DarkBard* <da******@extending-php.net> wrote in
news:D1********************@news3.tin.it:
Theo wrote:
hi all

this is probably another simple one, but the web doesnt seem to have
an answer that I can find.
Veeeery simple code. each row has 10 columns.

require('db.php');
$query = "SELECT * FROM mytable";
$result = mysql_query($query);
$numrows = mysql_num_rows($result);

for($x=0; $x<$numrows; $x++)
$row_arrays[$x] = mysql_fetch_array($result);

//test row 1
foreach($row_arrays[1] as $count)
print "$count<br>";

result for each print is the column number (0-9) and each
id(0,a,1,b,2,c etc). But if I use mysql_fetch_array($result,
'MSQL_ASSOC') as the docs say, I get the 'The result type should be
either MYSQL_NUM, MYSQL_ASSOC or MYSQL_BOTH' error. No quotes,
additional error about undefined constant. I figure using this would
get the array including the id only and not include the number.
Perhaps its the wrong assumption?

thanks

Hi,

the second parameter of mysql_fetch_array function must be an INTEGER.
MYSQL_BOTH, MYSQL_NUM and MYSQL_ASSOC are contants and have to be
specified without single or double quote.

bye


Hi thanks, yes I tried that as well.

but this morning (I always think better in the late mornings) I used
mysql_fetch_assoc instead and all is good.

However, on the fetch_array method, when I used MYSQL_ASSOC alone (first
way I tried it) I get the undefined constant error. Well ok not an error, a
notice - "PHP Notice: Use of undefined constant MSQL_ASSOC - assumed
'MSQL_ASSOC'"It looks like it doesnt know what this constant is, so its
changing it to a string. Question is why its not identifying the constant.
Academic now but I dont like it when simple functions dont work they way
they are supposed to... just bugs me because I might need it later :-)

cheers!
Jul 17 '05 #3

P: n/a
On Sat, 23 Oct 2004 17:23:58 -0000, Theo <in*****@noemail.com> wrote:
when I used MYSQL_ASSOC
Use of undefined constant MSQL_ASSOC


Spot the difference...

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #4

P: n/a
Andy Hassall <an**@andyh.co.uk> wrote in
news:k1********************************@4ax.com:
On Sat, 23 Oct 2004 17:23:58 -0000, Theo <in*****@noemail.com> wrote:
when I used MYSQL_ASSOC
Use of undefined constant MSQL_ASSOC


Spot the difference...

That loud sound you hear is me going

doh!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!

I knew it was going to something stupid I did ;o)
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.