Is there a better way to do SELECT queries in MySQL and sort them in PHP than this way?
- by Kent
I am just learning PHP/MySQL, one this I am having to do a lot is displaying data that was previously inserted into the database out to the user's browser. So I am doing this:
$select = mysql_query('SELECT * FROM pages');
while ($return = mysql_fetch_assoc($select))
{
$title = $return['title'];
$author = $return['author'];
$content = $return['content'];
}
then I can use these variables through out the page. Now, doing it the above way isn't an issue when I only have 3 columns in a database but what if I am dealing with a huge database with many more columns.
I have a nagging feeling that the pros do it in some more efficient way where they maybe loop through the table they are selecting from to find all columns it has and associate them with variables automatically. Is that the case? or is the above how you guys do it too?