This is a discussion on mysql_fetch_array problem within the PHP Language forums, part of the PHP Programming Forums category; Matthew Robinson wrote: > oh ye, just realised i didn't mention that the database has 2 rows, both > ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Matthew Robinson wrote:
> oh ye, just realised i didn't mention that the database has 2 rows, both > with the 'name' column not null, so the output should be different to what > it is. When you do $sql = 'select col1, col2, col4 from table'; $obj = mysql_query($sql) or die(mysql_error()); $res=mysql_fetch_array($obj); // $res as as many elements as columns in your select, and their // index is the name used in the select. // so, now you can do echo $res['col1'], $res['col2'], $res['col4']; // but echo $res['col3']; // does not work even if the table has a column named "col3" -- --= my mail box only accepts =-- --= Content-Type: text/plain =-- --= Size below 10001 bytes =-- |
|
|||
|
CODE:
<?php $dbcnx = @mysql_connect("SERV", "USR", "PWD"); $select = @mysql_select_db("houseproudlancs_co_uk1"); echo ("START<P><HR>"); $command = 'SELECT id, name, description, price FROM stock'; $qresult = mysql_query($command) or die(mysql_error()); while ($row = mysql_fetch_array($result)) { echo ($row ["name"]); echo ("<br>"); } echo ("<P><HR><P>END"); ?> OUTPUT: START Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/houseproudlancs_co_uk/index_to_be.php on line 17 END |
|
|||
|
Matthew Robinson wrote:
> $qresult = mysql_query($command) or die(mysql_error()); $qresult here > while ($row = mysql_fetch_array($result)) { but here you have $result > Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/houseproudlancs_co_uk/index_to_be.php on line 17 $result is *not* an object returned from mysql_query() function :) -- --= my mail box only accepts =-- --= Content-Type: text/plain =-- --= Size below 10001 bytes =-- |