View Full Version : Getting information from a mySQL database.

01-06-2006, 12:09 AM
Thanks to all the people who helped me connect to a mySQL database, but now, im having problems with actually getting information from the database, I've tried diffrent functions, but I'm still unsuccessful. Is there a function used for getting information from a table in a mySQL database, and also, I'm using phpAdmin, so I'm wondering if I'm actually adding information correctly to the field in that specific table.

Thank you for reading.

Velox Letum
01-06-2006, 01:52 AM
First you run the query, then use mysql_fetch_array() (http://www.php.net/function.mysql-fetch-array) (or mysql_fetch_assoc() (http://www.php.net/function.mysql-fetch-assoc) which is just mysql_fetch_array($result, MYSQL_ASSOC)):

$link = mysql_connect('localhost', 'user', 'pass');
$query = mysql_query('SELECT * FROM users');

// To fetch a single row we'd just get rid of the while loop...
while ($row = mysql_fetch_array($query) {
echo 'User: ' . $row['username'] . '<br />'; // This would be the usename column

This simple little snippit would connect to a database, select the db, run a query to select all columns in the users table, and then loop through each row, outputting the username.