Quote:
Originally Posted by jfk1
hmmm... this code produces "database error" without single quotes round $forum_name in the query
|
Overlooked that, sorry

.
Quote:
Originally Posted by jfk1
could i ask another question please?
this code (immediately above) doesnt have an "if" condition in it, as i previously had.... does this matter? what would happen it the query fails (no match in the db)?
|
I only corrected Marco's code, but yes, you should check the data exists.
PHP Code:
// "Comments should precede the code they describe, rather than following it."
// "Variables should not be quoted if they do not need to be."
$forum_name = $pagetitle;
// Not necessary to separate into newlines if not long, but it looks better aesthetically.
$row = $db->query_first("
SELECT forumid
FROM " . TABLE_PREFIX . "forum
WHERE title = '$forum_name'
LIMIT 1
");
if (!empty($row))
{
// "Strings should be quoted with single quotes if they contain no variables or control characters, otherwise use double quotes."
// "The choice between using string evaluations or string additions is yours to make, depending upon the circumstances."
// "Array keys should be quoted if they are strings or variables, even if you know that the variable evaluates to an integer. Quoting should follow the same rules as defined for string quoting."
$forum_link = '<a href="/forums/forumdisplay.php?f=' . $row['forumid'] . '">' . $forum_name . ' Forum</a>';
// This is also OK
$forum_link = "<a href=\"/forums/forumdisplay.php?f=$row[forumid]\">$forum_name Forum</a>";
}