print a column

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
devil_online
Forum Newbie
Posts: 5
Joined: Sun Feb 08, 2004 1:07 pm

print a column

Post 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
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post 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']
}
Post Reply