by furiousweebee » Sat Feb 15, 2003 3:16 pm
Ok here's what I've got: (sorry for the length)
-----------------------
<?
$db_name = "******";
$table_name = "advertising";
$connection = @mysql_connect("localhost", "******", "******")
or die("Couldn't connect.");
$db = @mysql_select_db($db_name, $connection)
or die("Couldn't select database.");
$sql = "SELECT id, banner_url, banner_h, banner_w, banner_alt, banner_link
FROM $table_name
ORDER by rand() LIMIT 1
";
$result = @mysql_query($sql,$connection)
or die("Couldn't execute query.");
$num=mysql_numrows($result);
$i=0;
while ($i < $num) {
$banner_url=mysql_result($result,$i,"banner_url");
$banner_h=mysql_result($result,$i,"banner_h");
$banner_w=mysql_result($result,$i,"banner_w");
$banner_alt=mysql_result($result,$i,"banner_alt");
$banner_link=mysql_result($result,$i,"banner_link");
?>
-----------------------
Then putting the variables into the page:
-----------------------
<a href="http://<? echo "$banner_link"; ?>" target="_blank"><img src="http://<? echo "$banner_url"; ?>" width="<? echo "$banner_w"; ?>" height="<? echo "$banner_h"; ?>" alt="<? echo "$banner_alt"; ?>" border="0"></a>
-----------------------
Then iterating
-----------------------
<?
++$i;
}
?>
----------------------------------------------
So can anyone tell me where I've gone wrong? I'm a bit of a novice, sorry.