PDA

View Full Version : Last Button for a PHP based comic



Scuzzball
2011-02-22, 09:03 PM
I'm trying to get a working PHP script for a comic, but I'm not sure of the "correct" way to get the last comic. Also, comic names. Should I just have the comic number and names in a MySQL database? Or some other method?

Andraste
2011-02-23, 12:09 AM
(This should probably be in Friendly Banter)

I suggest making a "latest" page in addition to each of the numbered ones, where you just display the most recent comic, updating it each time. This would mean the latest comic would be viewable either by going to the latest page, or the number for the latest page.

I'm fairly sure there's a better way, that's just what comes to mind with my limited knowledge of PHP.

Whoracle
2011-02-23, 02:23 AM
you make one row for each comic in your database, then the following php code will get you the latest one:


function getLatestComic() {
// In order for this to work, you'll need a valid column named "post_date" in
// your SQL-table with the type "date"
$sql = "SELECT whatever FROM comic_table ORDER BY post_date DESC LIMIT 1";
$query = mysql_query($sql) or die("Error: " . mysql_error());
$return = mysql_fetch_array($query, MYSQL_ASSOC);

// this will give you the "$return" array containing your comic data
// indices are the names of the table columns from comics_table,
// e.g. $return["date"] or $return["image"]
}

$myComicDataArray = getLatestComic();

If you have any more questions, PM me.

NerfTW
2011-02-23, 12:23 PM
You can also do it with a php script without a database by taking the current date, and going backwards one day (or whatever increment you update in) until a valid file that exists in your comic directory is found.

As in

date = today's date
newest = strip + date + .gif (or whatever)
open newest
If newest does not exist,
do
date = date - interval (usually one day)
newest = strip + date + .gif (or whatever)
open newest
while newest does not exist

This actually runs VERY fast for most comics. If your comic is going over a year without updating, you should probably just declare it dead and hard code the date.

Walrus
2011-02-24, 04:24 PM
There are a bunch of WordPress themes (ComicPress is probably the most well-known, but there are a few others which I can't recall the name of right now) that use PHP to run webcomics. You might want to download one of those and check out the code, there might be something in there that can help you out.

Scuzzball
2011-02-25, 07:35 AM
You can also do it with a php script without a database by taking the current date, and going backwards one day (or whatever increment you update in) until a valid file that exists in your comic directory is found.
The problem is that I'm not using date, I'm using numbers. I think I'll just do a similar thing in a MySQL table and just find the largest value, as Whoracle suggested. This way I can also put in names for the comics, or at least have that capability.