What this is for is the front page for a forum, and I want to get all of the details from the last post, ie name, time and also how many posts there are in that forum.
It all works outside a function but I can't get it to work inside one. Anyway, here's the function:
function getDetails($forum) {
$sql = "SELECT * FROM ".$forum;
$result = @mysql_query($sql);
if ($result) {
$numPosts = @mysql_num_rows($result);
$sql .= " ORDER BY date DESC LIMIT 0, 1";
$result = @mysql_query($sql);
if ($result) {
while ($row = @mysql_fetch_array($result)) {
$name = $row["name"];
$dateTime = $row["date"];
}
if ($numPosts > 0) {
$name = eregi_replace(" "," ",$name);
$year = substr($dateTime,2,2);
$month = substr($dateTime,4,2);
$date = substr($dateTime,6,2);
$hour = substr($dateTime,8,2);
$min = substr($dateTime,10,2);
$output = "<p>".$name."</p>\n<p>".$date."-".$month."-".$year."<br>".$hour.":".$min." GMT</p>";
}else{
$numPosts = 0;
$output = "<p align=\"center\">-</p>";
}
}else{
$numPosts = 0;
$output = "<p align=\"center\">-</p>";
}
}else{
$numPosts = 0;
$output = "<p align=\"center\">-</p>";
}
}
And I would call and use the function something like:
getDetails("forum_one");
echo "Posts: ".$numPosts;
echo "Last post: ".$output;
It's a problem with constructing the SQL query, or calling the function (or both?) I just want it all in a function so I don't have a heap load of code to deal with.
Thanks
Ste