I have a page on my testing site where users can post news. The posting page has a title, link, and body. The link can be left optional. I wanted the page to turn out that if a link was provided, it would make an <a> tag around the title, but if no link was provided, it would simply display the title. This is how I tried to do that.

//query the db
$getnews = mysql_query("SELECT * FROM news ORDER BY $order") or die(mysql_query());

while ($row = mysql_fetch_assoc($getnews))
{

//get data
$id = $row['id'];
$title = $row['title'];
$link = $row['link'];
$body = $row['body'];
$date = $row['date'];
$rating = $row['rating'];
$poster = $row['poster'];


echo "<a href='rate.php?id=$id'>&oplus;</a> <b>($rating) ";

if ($link="nolink") {
    echo $title;
} else {
    echo "<a href='$link' target='_blank'>$title</a>";
}

echo "</b> by $poster<br>
<font size='2'>($date)</font>
";

echo nl2br($body);

echo "<hr>";

}

It didn't work and I can see why, but I do not know what method I should be using.

Member Avatar for Zagga

Hi atalkingfish,

Try changing line 19 of your code to:

if ($link=="nolink") {

By golly, that worked! I can't believe I didn't think of that. Thank you very much!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.