I would recommend what brainpipe said with a few differences.
First is to use two functions instead of one. The first one will be your mysqlBuildQ() function with slight modifications.
PHP Code:
function mysqlBuildQ( $table, $cols, $order='', $desc=0, $where ) {
$select = "SELECT";
// expand $cols array
for ( $i=0; $cols[$i] != ''; $i++ ) {
if ( $i != 0 ) { $select = $select . ','; }
$select = $select . " $cols[$i]";
}
$select = $select . " FROM ";
$select = $select . $table;
if ( $where ) { $select = $select . " WHERE $where"; }
if ( $order ) { $select = $select . " ORDER BY $order"; }
if ( $desc ) { $select = $select . " DESC"; }
$query = mysql_query($select);
return $query;
}
You'll notice the only thing changed is what was returned. I am returning the whole result set.
The second function we'll call mysqlReturnResult()
PHP Code:
function mysqlReturnResult($resultSet) {
return mysql_fetch_array($resultSet);
}
Then you can change your loop code to the following.
PHP Code:
$news_cols = array('ID', 'Headline', "DATE_FORMAT(DateTime_Updated, '%m/%d %l:%i %p')");
$queryResult = mysqlBuildQ('News', $news_cols, 'DateTime_Updated', 1);
while ( $news_row = mysqlReturnResult($queryResult)) {
$news_id = $news_row[0];
$news_headline = $news_row[1];
$news_date = $news_row[2];
echo("<option value=\"$news_id\">$news_headline | $news_date</option>");
}
I thought I would post an article about data access objects that might interest you:
http://www.phppatterns.com/index.php...leview/25/1/1/
What you are doing is already a rudimentary version of what harry suggests in this article.
Bookmarks