hey people,
I'm having trouble getting my head round an advert system im trying to make.
I have a number of rows in a table that have the following field names:
id
Page
Artist
TopImage
I want to be able to display the TopImage depending on the Page and Artist
The page name and artist name will be set by variables in the URL, for example:
...domain.com/index.php?page=review&artist=thewho
What I want to say is:
If the rows Page is equal to review and artistis equal to thewho then dsplay the TopImage, but if the Page is equal but the artist isnt then randomly pick a row where the page is equal to the page in the url, but if the artist is equal and the page isnt then randomly pick a row that has that artist. And, if none are set then randomaly select a row that has TopImage set.
Sorry if thats a bit hard to understand.
I have tried making it, but soon realised I was going about it the wrong way.
heres what I have:
<?php
include('dbconnect.php');
$TableName = 'Adverts';
$addir = 'Adverts/';
$page= $_GET['page'];
if (empty($page)){ $page = 'home'; }
$artist = $_GET['artist'];
// Build SQL Query
$query = "select * from $TableName order by id DESC";
$numresults=mysql_query($query);
$numrows=mysql_num_rows($numresults);
// If we have no results, offer a google search as an alternative
if ($numrows == 0) {
echo 'There are no entries yet...';
}
//set up layout
$l1 = '<div align="center"><a href="';
$l2 = '" target="_blank"><span class="adimages"><img src="';
$l3 = '" border="0"></span></a></div>';
// get results
$result = mysql_query($query) or die("Couldn't execute query");
// now display the results returned
while ($row= mysql_fetch_array($result)) {
//Top Advert
if (!empty($row['TopImage'])){
if ($row['Page'] == $page){
if ($row['Artist'] == $artist){
$TopAdvert = $l1.$row['TopLink'].$l2.$addir.$row['TopImage'].$l3;
}
else {
//Pick a random ad where page is equal to menu name
$TopAdvert = $l1.$row['TopLink'].$l2.$addir.$row['TopImage'].$l3;
}
}
else {
//Page isn't equal to menu name
if ($row['Artist'] == $artist){
$TopAdvert = $l1.$row['TopLink'].$l2.$addir.$row['TopImage'].$l3;
}
else {
//Pick a random ad where TopImage is set
$TopAdvert = $l1.$row['TopLink'].$l2.$addir.$row['TopImage'].$l3;
}
}
}
else {
//There is no TopImage,
echo '';
}
}
?>
As you can see, this would only apply to the first row so I'm thinking I would need to add new queries within the while function where it would say wheather the page was equal to Page etc. then if a result was found then go on to the next query.
What I can't get my head around is first, am I asking the right questions in the correct order? and secondly, would my method actualy work?
Thanks for any help.