Non potrà mai funzionare, quel codice.
Invece prova con questo:
Codice PHP:
<?php
include('config.php');
$db = mysql_connect($db_host, $db_user, $db_pass);
mysql_select_db($db_name)or die("Cannot connect to database");
$query = mysql_query("SELECT * FROM banner ORDER BY RAND() LIMIT 1");
if($query){
if(mysql_num_rows($query) > 0){
$row_query = mysql_fetch_array($query);
echo '<a href="',$row_query['url'],'" target="_blank"><img src="',$row_query['img'],'" border="0"></a>';
}
else
echo 'Rows: 0';
}
else
echo mysql_error();
@mysql_close($db);
?>
LIMIT 1 -> estrae un record
LIMIT 2 -> estrae due record
ecc...
EDIT:
Se LIMIT è maggiore di 1, cioè LIMIT 2, LIMIT 3, LIMIT 4, ecc..., il codice diventa così:
Codice PHP:
<?php
include('config.php');
$db = mysql_connect($db_host, $db_user, $db_pass);
mysql_select_db($db_name)or die("Cannot connect to database");
$query = mysql_query("SELECT * FROM banner ORDER BY RAND() LIMIT 3");
if($query){
if(mysql_num_rows($query) > 0){
while($row_query = mysql_fetch_array($query))
echo '<a href="',$row_query['url'],'" target="_blank"><img src="',$row_query['img'],'" border="0"></a>';
}
else
echo 'Rows: 0';
}
else
echo mysql_error();
@mysql_close($db);
?>