Forum Moderators: coopster

Message Too Old, No Replies

"href" ing a random row from the databse

         

asson

2:48 pm on Oct 11, 2007 (gmt 0)

10+ Year Member



Hi,
I need a little help with this code,

<?php

mysql_select_db(database);

$query = "SELECT * FROM tag ORDER BY rand() LIMIT 50";

$result = mysql_query($query);

while ($row = mysql_fetch_array($result)) {
echo ($row['tag']).("&nbsp;&nbsp;&nbsp;");
}

mysql_free_result($result);
mysql_close();
?>


the code generated a random word/text from the database, I want evey work to be a Hyperlink to lets say http://www.example.com, can't fix it my self, hope you can help me.

something like this,
<a href="http://www.example.com/<?php echo ($row['tag']);?>.html"><?php echo ($row['tag']);?></a>

Thanks in advance.

[edited by: dreamcatcher at 3:28 pm (utc) on Oct. 11, 2007]
[edit reason] Use example.com, thanks. [/edit]

eelixduppy

8:37 pm on Oct 11, 2007 (gmt 0)



Something like this?

while ($row = mysql_fetch_array($result)) {
echo '<a href="http://www.example.com/'.$row['tag'].'.html">'.$row['tag']).'</a>';
}

asson

8:45 pm on Oct 11, 2007 (gmt 0)

10+ Year Member



Thank you, I tried with that before I wrote my post but got an error, witch I got now too.

Parse error: syntax error, unexpected ')', expecting ',' or ';' in C:\xampp\htdocs\php\t.php on line 11
-----
Update,
I removed the ) and it's working now, thanks alot.

[edited by: asson at 8:49 pm (utc) on Oct. 11, 2007]

eelixduppy

8:46 pm on Oct 11, 2007 (gmt 0)



oops...when I copied and pasted your code from the first msg I forgot to remove a parenthesis. The one line should be this:

echo '<a href="http://www.example.com/'.$row['tag'].'.html">'.$row['tag'].'</a>';

try that one :)

asson

8:49 pm on Oct 11, 2007 (gmt 0)

10+ Year Member



Update,
I removed the ) and it's working now, thanks alot.