Not fully given up on making the muser of the week thingy to work, but just given that a break for a while whilst I do my uni work. Replaced it with a nice random mugger bit which is alot easy, just calling random photos from the gallery. The muser of the week stored a random photo id onto a table and calls it everytime until the next time is made. Anyone who feels like they can tackle it, read on and give us a comment
This section is the muser of the week generation bit. It gets the latest photo by finding the maximum ID number (so the highest will be outputted). It then checks wither its past the week, and if it is it creates a new random photo id.
$query = "SELECT pid, MAX(randomID) as randomID,timestamp FROM randompic GROUP BY pid";
$result = mysql_query($query,$dblink) or die('Query failed: ' . mysql_error());
$line = mysql_fetch_array($result,MYSQL_ASSOC);
$randompic = $line['pid'];
$lateststamp = $line['timestamp'];
$daysleft = ceil((($lateststamp+604800)-time())/86400);
if((time()-604800)>$lateststamp){
mysql_select_db (”board”,$dblink);
$query = “SELECT pid FROM cpg132_pictures WHERE aid=1 ORDER BY RAND() LIMIT 1″;
$result = mysql_query($query,$dblink) or die(’Query failed: ‘ . mysql_error());
$line = mysql_fetch_array($result,MYSQL_ASSOC);
$newrandompic = $line['pid'];
$newstamp=$lateststamp+604800;
mysql_select_db (”randomiddb”,$dblink);
$query = “INSERT INTO randompic SET pid=’$newrandompic’, timestamp=’$newstamp’”;
$result = mysql_query($query,$dblink) or die(’Query failed: ‘ . mysql_error());
}
This bit simply calls the actual photo everytime, all this bit does is get the last photo and just displays it all there…
$query = "SELECT pid,title,filename,hits FROM cpg132_pictures WHERE pid='$randompic' LIMIT 1";
$result = mysql_query($query,$dblink) or die('Query failed: ' . mysql_error());
$line = mysql_fetch_array($result,MYSQL_ASSOC);
then it echo’s the stuff… cant put it here because it reads it as normal html, tried using the code tags, didnt work, bit gay hehe
March 19th at 2:43 pm
Think I’ve worked this out
I’ve done a more simple way where instead of inserting the new random mug into the table, you could just have one entry and it updates every week.
I’ve got the code here but just check that the fields and table names are correct coz I was testing it out on one of my databases and may have made a mistake when changing it back to your table names…
$query = “SELECT id, pid,timestamp FROM randompic”;
$result = mysql_query($query) or die(’Query failed: ‘ . mysql_error());
$line = mysql_fetch_array($result,MYSQL_ASSOC);
$id = $line['id'];
$randompic = $line['pid'];
$lateststamp = $line['timestamp'];
$daysleft = ceil((($lateststamp+604800)-time())/86400);
if((time()-604800)>$lateststamp){
$query = “SELECT pid FROM cpg132_pictures ORDER BY RAND() LIMIT 1″;
$result = mysql_query($query) or die(’Query failed: ‘ . mysql_error());
$wee = mysql_fetch_array($result,MYSQL_ASSOC);
$newrandompic = $wee['pid'];
$newstamp=$lateststamp+604800;
$query = “UPDATE randompic SET pid=’$newrandompic’, timestamp=’$newstamp’ WHERE id=$id”;
$result = mysql_query($query) or die(’Query failed: ‘ . mysql_error());
}
$query = “SELECT cpg132_pictures.id, cpg132_pictures.filename, randompic.pid FROM cpg132_pictures, randompic WHERE cpg132_pictures.id=randompic.pid LIMIT 1″;
$result = mysql_query($query) or die(’Query failed: ‘ . mysql_error());
$poo = mysql_fetch_array($result,MYSQL_ASSOC);
…then echo all your stuff out.