I have a question about the list() function that I could not find on php.net;
I am using the following code:
$query = "SELECT blog_id, title, entry, DATE_FORMAT(date_entered, '%M %e, %Y') AS formatted_date
FROM blog_entries ORDER BY blog_id DESC LIMIT 3";
if ($r = mysql_query ($query)) // Run the query.
{
// Retrieve and print every record.
while ($row = mysql_fetch_array ($r))
{
list($id, $title, $entry, $date) = $row;
//$date = date("F d, Y");
$title = htmlspecialchars($title);
$title2 = trim(strtolower(str_replace(' ', '-', $title)));
$entry = nl2br($entry);
$cut = substr($entry, 0, 300);
$new_text = substr($cut, 0, strrpos($cut, ' '));
echo "<h2>{$title}</h2>{$date}<br />
<p>{$new_text}<br /><a href=\"$title2.html\">View full story</a></p><br />";
}
echo '<a href="archive.php">View all News</a>';
}
else
{ // Query didn't run.
die ('<p>Could create the table because: <b>' . mysql_error() . "</b>. The query was $query.</p>");
} // End of query IF.
?>
It works perfect but my question is >>> do you have to define a variable for each row in the database? Will the list function not work!
So if i had 5 rows
userid
username
pass
realname
email
and I do this
list($userid, $username, $pass, $realname) = $row;
will that work or since the count is off, will it not work!
I am wondering this to find out if I can use this if we only want to list() certain fields!
Hope this make sense?
Regards,
Mike