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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
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 |
|
|||
|
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! |
|
|||
|
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 |
|
|||
|
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) |