/    Sign up×
Community /Pin to ProfileBookmark

PHP Site: Now for the REAL fun…

Now that I have a working PHP site, I’ve been wondering if the following is possible:

If I had some comics arranged in pages of five comics, and each comic was numbered like so:

[QUOTE]

[I]Page 1:[/I]
1: Comic A
2: Comic B
3: Comic C
4: Comic D
5: Comic E

[I]Page 2:[/I]
6: Comic F
7: Comic G
8: Comic H
9: Comic I
10: Comic J

[/QUOTE]

And I wished to insert Comic K into the list, somewheres on Page 1, could I get the comics to rearrange and renumber themselves on the pages like this?

[QUOTE]

[I]Page 1:[/I]
1: Comic A
2: Comic B
3: Comic C
4: Comic K
5: Comic D

[I]Page 2:[/I]
6: Comic E
7: Comic F
8: Comic G
9: Comic H
10: Comic I

[I]Page 3:[/I]
11: Comic J

[/QUOTE]

to post a comment
PHP

10 Comments(s)

Copy linkTweet thisAlerts:
@NogDogApr 02.2005 — I might do something like this:

Create a simple text file with each comic's file name listed on a separate line (with no blank lines in the file). As you add, delete, or rearrange comics, just edit this file to reflect the desired sequence of comic files.

You could then use 1 PHP file to display them 5 at a time, telling it which comic to start with via the URL, something like [color=DarkGreen][FONT=Courier New]comics.php?page=1[/FONT][/color].
[code=php]
<?php
$page = (isset($_GET['page'])) ? $_GET['page'] : 1 # default is page 1
$comics = file(comic_list.txt);
for($ix = $page * 5 - 5; $ix < $page * 5 and array_key_exists($ix, $comics); $ix++)
{
echo "<img src='{$comics[$ix]}' alt='comic'>n"; # add style etc. as desired
}
# previous/next stuff
if($page > 1)
{
echo "<a href='comics.php?page=" . $page - 1 . "'>Previous page</a>n";
}
if(count($comics) >= $page * 5)
{
echo "<a href='comics.php?page=" . $page + 1 . "'>Next page</a>n";
}
?>
[/code]
Copy linkTweet thisAlerts:
@Mr_Initial_ManauthorApr 02.2005 — Hmmmm... Here's the full HTML block that goes with each comic.

[CODE]
<dt><img src="./Comics/y1-sem1/URL" alt="Comic"></dt>
<dd class="number">Comic #X</dd>
<dd class="date1"><strong class="commenter">Drawn:</strong> DATE</dd>
<dd class="date2"><strong class="commenter">Appeared in CavDaily:</strong> DATE</dd>
<dd class="jdk"><strong class="commenter">JD Kraaikamp:</strong> Blah blah blah</dd>
<dd class="scott"><strong class="commenter">Scott Ruhl:</strong> Yackity Yack</dd>
[/CODE]


Will this screw things up?
Copy linkTweet thisAlerts:
@NogDogApr 02.2005 — Now I'm thinking you're really pointing toward using a database to store all the info, instead of a text file. You could still use the file, but you'd need to make it tab-delimited or a CSV file, perhaps; with each line having all the info you need. Whichever method, you'd still read in a record, but now you'd have to break out the parts and insert them into the HTML in their respective places.

If you expect this to expand to more than a few comics, I'd highly recommend the database approach, as this is generally a more dependable way to store data, plus it's very flexible: it would be relatively simple to change the order comics are displayed - by author, title, date, whatever you want.
Copy linkTweet thisAlerts:
@Mr_Initial_ManauthorApr 02.2005 — There are over 300 comics in all.

What I had thought of was taking each block of that HTML, putting it in an .htm file (I use HTM instead of TXT so that it opens up in Crimson Editor rather than notepad), and thus I'd have each block of HTML saved in seperate little files, and use them as inserts.

As for sorting them, I only REALLY need to do by date published (The comics will be numbered that way). Scott Ruhl was the author of all of them, and the date they were drawn on would create more than a few mixups.
Copy linkTweet thisAlerts:
@solomonApr 02.2005 — Blimey - that's a really long winded way of going about it! I'd avoid doing it that way at all costs... very time consuming! You can really save yourself a lot of effort (and hard drive space ?) if you do it more dynamically.

As NogDog suggests, a database would be your best solution but if you don't yet know how to use them fully and need a quick fix then a csv file would be your best bet

Create a file like this and save it as comics.csv (if you do it as a csv file and not txt then you can edit it in Excel or similar). It's got to have the correct read permissions but I'd've thought it'll get those automatically when you upload the file (ask someone else about that - I still get lost with permissions! ? )

[code=html]
1,images/image1.jpg,yesterday,tomorrow,Blah blah blah,Yackity Yack
2,otherimages/image2.jpg,last year,next week,yada yada,rhubarb rhubarb
[/code]


Make sure you keep all the fields in the right order and separate everythng by commas. Then you want a script like this:

[code=php]
<?php
$filename = "relative/path/to/csv/file/comics.csv";
$issue = file($filename);
foreach ($issue as $magazine => $values) {
$elements = explode(",",$values);
?>
<dt><img src="<?php echo $elements[1] ?>" alt="Comic"></dt>
<dd class="number">Comic #<?php echo $elements[0] ?></dd>
<dd class="date1"><strong class="commenter">Drawn:</strong> <?php echo $elements[2] ?> </dd>
<dd class="date2"><strong class="commenter">Appeared in CavDaily:</strong> <?php echo $elements[3] ?> </dd>
<dd class="jdk"><strong class="commenter">JD Kraaikamp:</strong><?php echo $elements[4] ?></dd>
<dd class="scott"><strong class="commenter">Scott Ruhl:</strong><?php echo $elements[5] ?></dd>
<?php
}
?>

[/code]


I've just tested it myself and it seems to work a treat although it'll need a bit of jigging around to deal with 300+ comics without frightening your visitors ? Good luck
Copy linkTweet thisAlerts:
@Mr_Initial_ManauthorApr 02.2005 — Create a file like this and save it as comics.csv (if you do it as a csv file and not txt then you can edit it in Excel or similar).[/QUOTE]

What if I don't HAVE Excel?
Copy linkTweet thisAlerts:
@solomonApr 02.2005 — then you can edit it in a text editor - a csv file is pretty universal - you can create a .txt file and simply rename it to .csv if you want. It's just that using excel (or similar spreadsheet software) allows you to not have to think about just how many commas you're putting in
Copy linkTweet thisAlerts:
@Mr_Initial_ManauthorApr 03.2005 — If you expect this to expand to more than a few comics, I'd highly recommend the database approach, as this is generally a more dependable way to store data, plus it's very flexible: it would be relatively simple to change the order comics are displayed - by author, title, date, whatever you want.[/QUOTE]

I [I]know[/I] it will run over 300 comics; I have 6 folders of 40-60 comics each.

Here's an actual example of one of the comics (The first comic, actually) with the relevant HTML block.

[CODE]<dt class="top"><img src="./Comics/y1-sem1/sadistic.gif" alt="Comic"></dt>
<dd class="number">Comic #1</dd>
<dd class="date1"><strong class="commenter">Drawn:</strong> May 3, '01</dd>
<dd class="date2"><strong class="commenter">Appeared in CavDaily:</strong> Wed. Aug. 29</dd>
<dd class="jdk"><strong class="commenter">JD Kraaikamp:</strong> And here we go, with the first Coach Random comic published in the Cavalier Daily. Comics running in the Cavalier Daily at the time: Blank Slate, Permanent Tanooki, Paradigm Shift, Action Daxton, Second Nature, Crazy Eskimo, Sketchy, Dangerzone, Drool, and, of course, Coach Random.<br>
And as for this strip, well... I guess he's not sadistic. Looks like it was a quick death... >.> <.<</dd>
<dd class="scott"><strong class="commenter">Scott Ruhl:</strong>
</dd>
[/CODE]



What I want, is for the comic number to change automatically, so that if I stick in a new comic, the numbers after it will adjust.

I know I don't know how to use databases, but this site's very much a learning experience, so if you guys wanna show me how to do one, that's good, too.

From what Solomon showed me, it looks like a CSV file could get clumsy in a hurry.
Copy linkTweet thisAlerts:
@solomonApr 04.2005 — 
As NogDog suggests, a database would be your best solution but...
[/QUOTE]

? I know

[URL=http://uk.php.net/manual/en/ref.mysql.php]This page is very helpful[/URL] - and try [URL=http://www.mysql.com/]this site[/URL]
Copy linkTweet thisAlerts:
@Mr_Initial_ManauthorApr 04.2005 — Yeah, I don't think a quick fix would exactly work on something this size. :-/
×

Success!

Help @Mr_Initial_Man spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...