I'm afraid I have another MySQL problem. My second thread of the day... sorry about this everyone.
http://namcocentral.com/phpBB3/header-adverts.php
The page above is supposed to call adverts from my database. But I've messed up the code horribly, and it doesn't work.
<html>
<head></head>
<body>
<?php
//This establishes database connection
//Change details before giving code
mysql_connect ("xxxx", "xxxxxx", "xxxx") or die ('Error connecting to mysql');
mysql_select_db ("xxxx");
// Loads random advert from database
$query_first="SELECT (URL, Image, Impressions) FROM test_ads WHERE (Impressions > 0) ORDER BY rand() LIMIT (0,1)";
if ($query_first == false) {
// No ads:
die('No ads');
}
else
{
$link = $query['URL'];
$image = $query['Image'];
// Display ad:
echo "<a href=\"$link\"><img src=\"$image\" alt=\"Ad Banner\" style=\"border:0;\" width=\"728\" height=\"90\" /></a>";
// Minus 1 from amount of impressions
$query = ("UPDATE test-ads SET (Impressions = Impressions - 1) WHERE adid = " . $ad['Impressions']);
}
?>
<br /><a href="#">Advertise with us!</a>
</body>
</html>
Where have I gone wrong? My code selects the three things I need from the table test_ads (which are URL, Image, Impressions). It then tries to put those as a variable. But things don't work from there. On top of that, my code is meant to reduce the integer Impressions by 1, every time the page is accessed. This does not occur.