Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: PHP Question

  1. #1
    david622's Avatar Procrastinator
    Join Date
    Jan 2004
    Location
    USA
    Age
    34
    Posts
    480
    I'll start this off by saying that I'm starting a new webcomic. Reading one of the threads in the Books/Comics subdivision in this forum I learned about offensivecomic.com

    I enjoy the comic, but what I'm interested in is the PHP behind the site. I looked at the source code but I don't think I'm picking up everything so I'm asking for your help.

    In the archives page of offensivecomic.com, each comic link is to offensivecomic.com/?comic=XX

    This seems to make it at each click of the link the index page will load, same as always, but with the specified comic chosen in the body of the page. This is nice because you don't have to make 100 different HTML pages that contain the same content except for the actual comic.

    How do I assign these PHP comic numbers to each issue like that done in this site so I can make my own site that works in a similar way?

    I appreciate your help,
    david

    p.s. excuse this explanation, if you need me to clarify what I mean please say so.

    edit: also, how would I be able to make a "previous" button, so the comic number goes down by 1 from the current comic selected?
    Last edited by david622; 09-03-2005 at 01:39 AM.

  2. Internet, Programming and Graphics   -   #2
    SeK612's Avatar Poster BT Rep: +10BT Rep +10
    Join Date
    Nov 2002
    Location
    UK
    Posts
    718
    I'd also be interested in finding out how the exampleurl.com/?page=XX thing works. I've seen similar on lots of sites but haven't really found out how it funtions and the benifets of such a setup.

    Looking at the source code of a PHP page may not reveal a lot. As I understand it PHP that is executed often doesn't appear on the page after it's loaded and so won't show up in the source.

    For ease of editing and keeping certain things the same site wide (such as a navigation menu) you can used includes. These are code in a seperate file which you can place in your root directory and call to any page on your site. There may be a better way to do this though.

  3. Internet, Programming and Graphics   -   #3
    tesco's Avatar woowoo
    Join Date
    Aug 2003
    Location
    Canadia
    Posts
    21,669
    When you have a php extension on a page, and php on your server, then you can put
    ?variable=value
    Or for more than one variable
    ?variable1=value1&variable2=value2
    (they are seperated by '&')

    Now, in the php file all of those variables will be, for example, $_GET['variable1'] and $_GET['variable2'], and the value of them will be what is after the '=' sign.

    To work with these, your articles will have to be in some sort of php. The easiest way you can do this all in one page is to setup like this:

    PHP Code:
    <?php
         
    if ($_GET['comic'] == 1)
         {
    ?>
              INSERT THE HTML FOR THIS COMIC HERE
    <?php
         
    }
         else if (
    $_GET['comic'] == 2)
         {
    ?>
              INSERT THE HTML FOR THIS COMIC HERE
    <?php
         
    }
         else if (
    $_GET['comic'] == 3)
         {
     
    ?>
              INSERT THE HTML FOR THIS COMIC HERE
    <?php
         
    }
         else
         {
    ?>
              HTML FOR IF THERE IS NO ARTICLE WITH NAME/ID THEY SAID
    <?php
         
    }
    ?>
    etc.
    Note: The area between the <?php and ?> is the php code, anything outside of those tas will be treated as plain html code.

    An even better way is to store the articles in a database(mysql) but that takes some understanding of PHP to get going so it would be best if you stick with this unles you want to start reading some tutorials on php.

    I could also PM you some example sites that i've made that use mysql.
    Last edited by tesco; 09-03-2005 at 03:04 PM.

  4. Internet, Programming and Graphics   -   #4
    david622's Avatar Procrastinator
    Join Date
    Jan 2004
    Location
    USA
    Age
    34
    Posts
    480
    alright, thanks! so, if in the archives page for the comic, i just pasted this PHP there, it should do what I'm talking about? And also, how would I be able to do a "previous" button.

    i should probably add that i have no previous php knowledge ^_^,
    Last edited by tesco; 09-03-2005 at 03:08 PM. Reason: accidently edited instead of quote :P

  5. Internet, Programming and Graphics   -   #5
    tesco's Avatar woowoo
    Join Date
    Aug 2003
    Location
    Canadia
    Posts
    21,669
    Quote Originally Posted by david622
    alright, thanks! so, if in the archives page for the comic, i just pasted this PHP there, it should do what I'm talking about? And also, how would I be able to do a "previous" button.

    i should probably add that i have no previous php knowledge ^_^,
    The previous button will be
    <a href="index.php?comic=<?php echo $_GET['article']-1; ?>">Previous Article</a>
    Assuming you will be using numbers
    Last edited by tesco; 09-03-2005 at 03:08 PM.

  6. Internet, Programming and Graphics   -   #6
    david622's Avatar Procrastinator
    Join Date
    Jan 2004
    Location
    USA
    Age
    34
    Posts
    480
    alright thanks

    i'll let you know how this works out when i try it

  7. Internet, Programming and Graphics   -   #7
    sparsely's Avatar °¤°¤°¤°¤°¤°¤°
    Join Date
    Dec 2002
    Location
    static hum
    Posts
    3,486
    in such a case, you would be much safer using a switch.

    PHP Code:
    switch($_GET['comic'])
    {
             case 
    1:
                
    // show #1
                
    break;
             case 
    2:
               
    // etc
               
    break;
             default:
              
    // something;

    Last edited by sparsely; 09-03-2005 at 07:42 PM.

    this post is guaranteed 100% parrot-free

  8. Internet, Programming and Graphics   -   #8
    david622's Avatar Procrastinator
    Join Date
    Jan 2004
    Location
    USA
    Age
    34
    Posts
    480
    Before I actually start making the page, I'm a bit confused about a couple things.

    Firstly, rossco, I'm wondering, would this code you posted before go in an archives page? And what would go on the "current issue" index page to display the current comic?

    Maybe if I could see an example source code it woule be much clearer. I appreciate your help, but I'm new to the PHP world. Rossco's code seems to be defining a number to each comic, but I'm not sure where this code would go.


    Second, sparsely's code confuses me b/c I'm not exactly sure what it's for. does it serve the same function as rossco's?

    please, explain each detail to me!

    i really appreciate the help,
    david

  9. Internet, Programming and Graphics   -   #9
    tesco's Avatar woowoo
    Join Date
    Aug 2003
    Location
    Canadia
    Posts
    21,669
    Sparsely's is the same idea as mine, just another way of doing it.
    I've never done switches before tho so i'm not sure if it's better.

    Mine would go in an index.php file or whatever name you want. All the comics are included in that one file, so you don't really need any other files other than css, images, etc.

  10. Internet, Programming and Graphics   -   #10
    sparsely's Avatar °¤°¤°¤°¤°¤°¤°
    Join Date
    Dec 2002
    Location
    static hum
    Posts
    3,486
    the problem with using uri parms in if statements is that someone could specify something other than what you want.

    with a switch there are a set of valid values, and that's all, and you can make a default action. and a switch would also be a bit faster than a series of ifelse's

    this post is guaranteed 100% parrot-free

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •