Page 1 of 1

print a column

Posted: Sun Aug 29, 2004 8:42 am
by devil_online
Hi, I want to print each element of a column of a mysql database.
For exemple to print the first element could we do like this:

Code: Select all

$result = mysql_query( "SELECT username FROM users" );
$row = mysql_fetch_array($result);
print $rowї1];
Thanks

Posted: Sun Aug 29, 2004 9:14 am
by malcolmboston
not sure what you mean but im guessing you want to get all rows of data....

Code: Select all

$query = "SELECT * FROM somewhere";
$result = mysql_query($query) or die (mysql_error());
$array1 = mysql_fetch_array($result, MYSQL_ASSOC);
// do something here with first recordset
// now gather second recordset
while ($array2 = mysql_fetch_assoc($result))
{
// notice the parethesis
// puit what you want to do with each record here
// for eg echo $array2['something']
}