mysql_fetch_array... interesting

This is a discussion on mysql_fetch_array... interesting within the PHP Language forums, part of the PHP Programming Forums category; hi all this is probably another simple one, but the web doesnt seem to have an answer that I can ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-23-2004
Theo
 
Posts: n/a
Default mysql_fetch_array... interesting

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
Reply With Quote
  #2 (permalink)  
Old 10-23-2004
Gabriele Farina *DarkBard*
 
Posts: n/a
Default Re: mysql_fetch_array... interesting

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
Reply With Quote
  #3 (permalink)  
Old 10-23-2004
Theo
 
Posts: n/a
Default Re: mysql_fetch_array... interesting

Gabriele Farina *DarkBard* <darkbard@extending-php.net> wrote in
news:D1qed.75867$b5.3649335@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!
Reply With Quote
  #4 (permalink)  
Old 10-23-2004
Andy Hassall
 
Posts: n/a
Default Re: mysql_fetch_array... interesting

On Sat, 23 Oct 2004 17:23:58 -0000, Theo <invalid@noemail.com> wrote:

> when I used MYSQL_ASSOC
>Use of undefined constant MSQL_ASSOC


Spot the difference...

--
Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Reply With Quote
  #5 (permalink)  
Old 10-24-2004
Theo
 
Posts: n/a
Default Re: mysql_fetch_array... interesting

Andy Hassall <andy@andyh.co.uk> wrote in
news:k19ln09cvv969tn2m0oc547n3vjr13807v@4ax.com:

> On Sat, 23 Oct 2004 17:23:58 -0000, Theo <invalid@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)
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 08:02 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0