mysql_fetch_array problem

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 > ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #11 (permalink)  
Old 01-07-2004
Pedro Graca
 
Posts: n/a
Default Re: mysql_fetch_array problem

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 =--
Reply With Quote
  #12 (permalink)  
Old 01-07-2004
Matthew Robinson
 
Posts: n/a
Default Re: mysql_fetch_array problem

id is the primary key, so i thought it would be best to use that as the
one to identify the row.

name is what i want to print to the screen.
Reply With Quote
  #13 (permalink)  
Old 01-07-2004
Matthew Robinson
 
Posts: n/a
Default Re: mysql_fetch_array problem

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
Reply With Quote
  #14 (permalink)  
Old 01-07-2004
Matthew Robinson
 
Posts: n/a
Default Re: mysql_fetch_array problem

sorry about the posting twice about the same thing again, but the line in
question is the one with while on it
Reply With Quote
  #15 (permalink)  
Old 01-07-2004
Pedro Graca
 
Posts: n/a
Default Re: mysql_fetch_array problem

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 =--
Reply With Quote
  #16 (permalink)  
Old 01-07-2004
Matthew Robinson
 
Posts: n/a
Default Re: mysql_fetch_array problem

thanks for the help pedro, im not used to programming properly, as i used
to program vb, which wipes your bum for you. anyway, thanks again. this
has been a problem for days.
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 07:13 AM.


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