Display News Function Problem
Posted: Tue Dec 23, 2003 8:12 pm
I am trying to display the news. In the mysql news table I have the user id of who posted it, so somehow I have to get the also query the user table for the information of the person with the specific id. I think this will work, but I am getting an error: "You have an error in your SQL syntax near '5`' at line 1". Any help is appreciated!
Here is my code so far...
Here is my code so far...
Code: Select all
<?php
//**********************************************************//
//StudentCenter //
//Display News Function Version 0.1 //
// //
//Written by: Rob Frawley //
//************************************* *********************//
require('config2.inc.php');
function displaynews($limit)
{
//query database for news
$news->query1 = "SELECT * FROM `news` ";
$news->query1 .= "ORDER BY `id` DESC ";
$news->query1 .= "LIMIT 0, `{$limit}`";
$news->result1 = mysql_query($news->query1) or die (mysql_error());
//display news
while ($row1 = mysql_fetch_array($news->result1)) {
//query database for poster info
$news->query2 = "SELECT * FROM `users` ";
$news->query2 .= "WHERE `id` = `{$row1['userid']}`";
$news->result2 = mysql_query($news->query2) or die (mysql_error());
$row2 = mysql_fetch_array($news->result2);
//display news
echo 'NEWS:' . '<br>';
echo '<u>' . 'Date:' . '</u>' . ' ' . $row1['timestamp'] . ' ' . '<u>' . 'Author:' . '</u>' . ' ' . $row2['firstname'] . ' ' .
$row2['lastname'] . '<br>';
echo $row1['news'];
}
}
displaynews(5);
?>