functions for returning entire rows of data:
mysql_fetch_array()
mysql_fetch_row()
mysql_fetch_assoc()
mysql_fetch_object()
from the php manual:
array mysql_fetch_array ( resource $result [, int $result_type ] )
meaning it returns an array,
usage would be like so:
$result = mysql_query("SELECT something, andthis FROM atable");
$row = mysql_fetch_array( $result );
$row would be
Array(
0 => 'somethings value',
'something' => 'somethings value',
1 => 'andthiss value',
'andthis' => 'andthiss value'
)
yes there would be 2, let me say that in english... TWO copies of every row, wasting alot of memory. This is why it is always important to specify result type (the second argument for mysql_fetch_array)
The 3 types are: MYSQL_BOTH, MYSQL_ASSOC, and MYSQL_NUM
MYSQL_BOTH is default when none else is specified and it means to return as both numerated and associative keys, never use this.
MYSQL_NUM returns a numerated array meaning it is an arrays which keys are incremented from 0
MYSQL_ASSOC returns an associative array meaning its keys will be the names of the columns selected.
mysql_fetch_assoc($result) is just like mysql_fetch_array($result, MYSQL_ASSOC)
mysql_fetch_row($result) is just like mysql_fetch_array($result, MYSQL_NUM)
mysql_fetch_object($result [, class name [, params]] ) returns an object, i dont have experience using this but more can be read at http://php.net/mysql_fetch_object
You can also get data from a mysql result set with mysql_result()
usage is mysql_result($result, $row, $column)
if you only SELECT one column, you can omit it in the function call.
$row is so you can jump to a row other than the first row returned. The first row is 0.
example:
$result = mysql_query("SELECT COUNT(*) FROM sometable");
$rowcount = mysql_result($result, 0);