TinyPortal

Development => Support => Topic started by: jozeta on January 14, 2008, 11:41:47 PM

Title: box scripting help
Post 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
Title: Re: box scripting help
Post by: jozeta on January 14, 2008, 11:58:27 PM
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>";
          }

Title: Re: box scripting help
Post by: G6Cad on January 15, 2008, 09:13:34 AM
You got it to work by removing the php tags on the first and last row right ;)