How would I go about programming a webcomic with dynamic hyperlinks, instead of having to hand-link everything?

I have no knowledge of PHP, FYI.
http://wordpress.org/extend/plugins/webcomic/
Walrus is another one.
Well, you can LEARN php Very Happy (that's what i did not too long ago)

Basically uh a php page is like a html page with special tags that let you do some cool stuff.

your url can have a 'parameter' aka variable. so like domain.com/index.php?p=1
so here the var p=1
you can access this var with the php command $_GET. so to store the page # in a variable "$cur" (all php vars are prefixed with $ and can basically be named anything you want) you have the line
Code:
$cur = $_GET['p']

Then you look at the superuseful php command 'echo'. Some people say echo is like print or Disp or Output, but that's not entirely truthful because what php does is it outputs an html document to send to the browser. that is why when you look at the source page of webcomic sites it looks like they hardcoded the links.

Anyway so you echo the page number you want into your hyperlink html

Code:
<a href="/index.php?p=<?php echo $cur+1; ?>">Next</a>
note the start and end tags of php are <?php and ?> and all php commands end in a semicolon.

Then to display your image you can do something like

Code:
<img src="/filepathname/<?php echo $cur; ?>.jpg" />
or whatever.

w3schools.com is a good place to learn about basic php syntax and stuff if you have any questions regarding that kind of thing.
And since many people here and on other calculator sites do web programming, you can ask around for help if you want to learn PHP.
Spyro543 wrote:
How would I go about programming a webcomic with dynamic hyperlinks, instead of having to hand-link everything?

I have no knowledge of PHP, FYI.
That should be very straightforward; all you really need is either a flatfile containing sets of comic, metadata or a simple MySQL database. If you need help finding your way into PHP, we'd be happy to help. Or as Nikky suggests, a content management system might do the trick.
I would strongly suggest just using an existing CMS as Nikky suggested.

Getting into PHP is easy enough but writing good PHP is rather more difficult. squidgetx's example looks simple, for example, but is susceptible to a cross-site scripting attack.
squidgetx wrote:
Well, you can LEARN php Very Happy (that's what i did not too long ago)

Basically uh a php page is like a html page with special tags that let you do some cool stuff.

your url can have a 'parameter' aka variable. so like domain.com/index.php?p=1
so here the var p=1
you can access this var with the php command $_GET. so to store the page # in a variable "$cur" (all php vars are prefixed with $ and can basically be named anything you want) you have the line
Code:
$cur = $_GET['p']

Then you look at the superuseful php command 'echo'. Some people say echo is like print or Disp or Output, but that's not entirely truthful because what php does is it outputs an html document to send to the browser. that is why when you look at the source page of webcomic sites it looks like they hardcoded the links.

Anyway so you echo the page number you want into your hyperlink html

Code:
<a href="/index.php?p=<?php echo $cur+1; ?>">Next</a>
note the start and end tags of php are <?php and ?> and all php commands end in a semicolon.


Code:
<img src="/filepathname/<?php echo $cur; ?>.jpg" />
Question: what is my filename going to be? 1.jpg?
^ yeah thats what it would be.

Also you can look up filters to restrict the value of p to prevent code/script insertion; I just gave the basic idea of what you might want to do.
Yeah, how would I go about making the script so that it stops increasing $cur when it reaches the newest comic?

Code:
<a href="?p=<?php
echo $cur + file_exists(($cur + 1) . '.jpg');
?>">Next</a>


This tests if the next image exists and echoes the link if it does, and the current page if not.
Better yet:


Code:
<a href="?p=<?php
echo $cur + file_exists((is_numeric($cur)?$cur:0 + 1) . '.jpg');
?>">Next</a>
Why would that be better?

I guess it would know if the page number is valid or not, but even if it isn't it would only ever output a number because of the addition, right?

And "0+1" is a strange way to do a one Wink
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement