Is there a better way to do SELECT queries in MySQL and sort them in PHP than this way?

Posted by Kent on Stack Overflow See other posts from Stack Overflow or by Kent
Published on 2010-12-28T01:42:15Z Indexed on 2010/12/28 1:54 UTC
Read the original article Hit count: 214

Filed under:
|

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?

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql