Hi all..
i am having a small problem that requires an expert's advise,
i am actually using php with ms sql, i know its not the best
compatibility choice!
i have managed to story images in folders and save their
corresponding id, url and extension information in the
database.
its working fine in every section by re constructing the image
path in accordance with each query!
however, part of the website is to deal with displaying
banners in the website in two sections; the top section
where there is only one banner on each page refresh,
and the side section where there is 5 banners on each page
refresh.
lets worry about the top one for now, where it retreives the
available banners to display in the database, select one of them
randomly and reconstruct the image path for that banner.
i am using the following script to select the banner to be
displayed, saved as bannerad.php:
<?php
session_start();
include("../phpscript/database.php");
$sql = "SELECT AD_ID, AD_URL, EXT, AD_COUNT, START_DATE "
."FROM Banners "
."WHERE (START_DATE BETWEEN DATEADD(M, - 1, GETDATE()) AND GETDATE()) AND (TYPE = 't') AND (ACTIVE = 1) ";
$rs = db_query($sql);
$rsc = db_result_count($sql);
$no=rand(1,$rsc);
$x=1;
while(!$rs->EOF)
{
if($x == $no)
{
$aid = $rs->Fields["AD_ID"]->value;
$nac = $rs->Fields["AD_COUNT"]->value + 1;
$aurl = $rs->Fields["AD_URL"]->value;
$sql = "Update banners set AD_COUNT = $nac where AD_ID = $aid";
db_query($sql);
echo file_get_contents("../ad_images/bt". $rs->Fields["AD_ID"]->value .$rs->Fields["EXT"]->value);
break;
}
$x++;
$rs->MoveNext();
}
?>
this script is called within the following image tag; which
resides in the headder section in the website:
<a href="#"><img src="scripts/bannerad.php" alt="" width="100%" height="64"></a>
what would be the best way to retreive the corresponding url
for each image?
i have tried a method in which i added a new colum in the databse, call it "flag"; which has a default value of 0,
and evertyime the script runs, i.e. on every page refresh it sets,
the flags value to 1, using:
$sql = "Update banners set FLAGS = 1 where AD_ID = $aid";
and added the following for the image tag:
<?php
$sql = "SELECT AD_ID, AD_URL, EXT, AD_COUNT, START_DATE "
."FROM Banners "
."WHERE (START_DATE BETWEEN DATEADD(M, - 1, GETDATE()) AND GETDATE()) AND (TYPE = 't') AND (ACTIVE = 1) AND (FLAGS = 1)";
$rs = db_query($sql);
$aurl = $rs->Fields["AD_URL"]->value;
$sql = "Update banners set FLAGS = 0";
$rs = db_query($sql);
?>
<a href="<?php echo "$aurl"; ?>"><img src="scripts/bannerad.php" alt="<?php echo "$aurl"; ?>" width="100%" height="64"></a>
it works, but not as expected, do you know why? 😕
its because the script runs ahead of the url!
i.e. everytime the url is retrevied, the script runs again after
it due to the sequence < a href"1"><img src="2"></a>
what am i doing wrong in the above code?
is that a good practice? or a bad one?
any advise please?