TinyPortal
Development => Support => Topic started by: jozeta on January 14, 2008, 11:41:47 PM
hi
i wannted to make a script that collects random links from the db.
the script works when its in a standalone phpfile, but not in the tpbox.
my knowlege of smf/tp integration is very limited, please help me
<?php
// ansluter till databasen
$opendb = mysql_connect("localhost", "xxxxxx", "xxxxxxx") or die(mysql_error());
mysql_select_db("xxxxxxxx") or die(mysql_error());
// hämtar information från den angivna tabellen
$result = mysql_query("SELECT * FROM smf_links ORDER BY RAND() LIMIT 5")
or die(mysql_error());
// hämtar resultatrader från tabellen
while($row = mysql_fetch_array( $result ))
{
// skriver ut innehållet radvis
echo "<a href='";
echo $row['url']."' target='blank'>";
echo $row['title']."</a><br>";
}
// stänger databasen
mysql_close($opendb);
?>
i understand that the db code is the problem, but what should it be?
please help
best regards johan
hehhe got it to work now...
so if any one is intrested and got the SMF link mod
here is a script that displayse x number of random links
global $db_prefix, $scripturl;
$query = db_query(
"SELECT *
FROM smf_links
ORDER BY RAND() LIMIT 5");
while ($row = mysql_fetch_array( $query ))
{
// print results
echo "<a href='";
echo $row['url']."' target='blank'>";
echo $row['title']."</a><br>";
}
You got it to work by removing the php tags on the first and last row right ;)