[PHP/MySQL]making links

Hello. I have connected to my database, and I have it print out the data it gets. but How do I make it so that instead just printing the text it makes it a link to a URL that includes part of another colom in the same row? Like the forums use. \

assuming $link_url and $link_title are your variables from the table…

echo '<a href="'.$link_url.'" title="'.$link_title.'">'.$link_title.'</a>';

well it kinda works now, but when it test it, it uses the word ‘.$link_title.’ instead of the accuall title from the database.:frowning:

right. the example i wrote assumes that’s what the variable is. you said you could echo out the data correctly, so i assumed you would know to replace the variable names i gave you with the correct ones from the db.

what is your php that you use to echo out the data from the db?

<?php
// Connect to server and select databse
mysql_connect("$host", “$username”, “$password”)or die(“cannot connect”);
mysql_select_db("$db_name")or die(“cannot select DB”);

$sql=“SELECT * FROM $tbl_name WHERE forum_id = 39 ORDER BY topic_id desc limit 5”;
$result=mysql_query($sql);

// Define $color=1
$color=“1”;

echo ‘<table width=“400” border=“1” align=“center” cellpadding=“2” cellspacing=“0”>’;
while ($rows=mysql_fetch_array($result)){

// If $color==1 table row color = #FFC600
if($color==1){
echo “<tr bgcolor=’#FFC600’>
<td>”.$rows[‘topic_title’]."</td>
</tr>";
// Set $color==2, for switching to other color
$color=“2”;
}

// When $color not equal 1, use this table row color
else {
echo “<tr bgcolor=’#ff9900’>
<td>”.$rows[‘topic_title’]."</td>
</tr>";
// Set $color back to 1
$color=“1”;
}

}
echo ‘</table>’;
mysql_close();
?>

I did put in my own variables. but it did as I said. this makes it go like this: www.blazes816.com/news.php. But where the titles are (topic_title) I want those to be links, linking to www.blazes816.com/forums/veiwtopic.php?t=(here I need the number from the column ‘topic_id’)

Please help if you can. I’ve been working on this for 3 days.

ah yes, a classic example of using the wrong quotation marks. you should be using single quotes for strings. that way, you can use double quotes within your strings without having to use escape characters. also, in html, the attributes for tags should be set within double quotes. here is the middle part of your code fixed up.

<?php
//the beginning...

// If $color==1 table row color = #FFC600
if($color==1){
echo '<tr bgcolor="#FFC600">';
echo '<td>'.$rows['topic_title'].'</td>';
echo '</tr>';

// Set $color==2, for switching to other color
$color="2";
}

// When $color not equal 1, use this table row color
else {
echo '<tr bgcolor="#ff9900">';
echo '<td><a href="http://www.blazes816.com/forums/viewtopic.php?t='.$rows[topic_id].'" title="'.$rows[topic_title].'">'.$rows[topic_title].'</td>';
echo '</tr>';
// Set $color back to 1
$color="1";
}

//... the rest
?>

THANK YOU SO MUCH! IT WORKS! IT WORKS!

don’t take this the wrong way, but I love you.

no problem.