Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 14 of 14

Thread: Comic help.

  1. #1
    New Coder
    Join Date
    Feb 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Comic help.

    My comic script won't work.

    PHP Code:
    <!--  Comment xOMG!!
    <?php
    /* $_COMIC[""] is just a magic quote. 
    I'll call it "a fake array". lol */
    $comic_id "1";
    $_COMIC["image"] = '"comic'$comic_id .'.png"';
    /* Can a magic quote equal a variable?
    Apparently...
    Now what else? 
    Oh yes, the comic title*/
    $comic_title "Nothing";
    $_COMIC["name"] = "Comic #"$comic_id ." "$comic_title ."- Megaman Generations";
    function 
    comic()
    {
    if (
    $comic_id "1")
    {
    $comic_title "- The Beggining ";}
    };
    comic();
    ?> -->
    <table>
    <tr class="header"><td><center><b><?=$_COMIC["name"]?></b></center></td></tr>
    </table>
    $comic_title won't change!! WHYYYYYY!!!! No, really.

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    It did change, you're just not displaying the change. You're displaying $_COMIC["name"], which is put together before you call the function comic(). Besides which, the scope of your variable $comic_title inside that function makes it a different variable than the $comic_title outside the function, so anything you do to $comic_title inside the function won't have any effect on the variable $comic_title outside the function. You can use "global $comic_title;" at the beginning of the function to solve that, or better yet return $comic_title.

    And finally,
    PHP Code:
    if ($comic_id "1"
    Is not checking to see if $comic_id is equal to "1"; it is assigning "1" to $comic_id, which returns "true" every time, which means that "if" statement will always evaluate to "true". You need to do use double equal signs, if ($comic_id == "1"), to see if $comic_id is equal to "1".

  • #3
    New Coder
    Join Date
    Feb 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Oh, thank you so much! I'm sooo happy!!

  • #4
    New Coder
    Join Date
    Feb 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It still doesn't work. I then edited it for I dunno how long so I just tried to change it a little.

    PHP Code:
    <?php

    //this displays the comic and title

    $_COMIC["id"] = "1";
    $_COMIC["image"] = 'comics/comic'$_COMIC["id"] .'.png';
    $_COMIC["title"] = "php script error: comic title not working.";
    $_COMIC["name"] = "Comic #"$_COMIC["id"] ." "$_COMIC["title"] ."- Megaman Generations";
     if (
    $_COMIC["id"] == "1")
      {
    $_COMIC["title"] = "The Beggining";}
    ?>
    <table>
    <tr class="header"><td><center><b><?=$_COMIC["name"]?></b></center></td></tr>
    <tr bgcolor="#6495ED"><td><center><img src=<?=$_COMIC["image"]?> alt="No comic"></center></td></tr>
    </table>
    Still not changing. Anything I tell to change in the "if" thingy won't change. It it becasue there's no function? When I do that, I move all of the variables into it. Then nothing show up. I put function(); at the end of the script too.
    Last edited by megajosh2; 08-23-2006 at 09:20 PM.

  • #5
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    what are you expecting to happen? to explain line by line:

    PHP Code:
    $_COMIC["id"] = "1"
    you set the id to be 1.
    PHP Code:
    $_COMIC["image"] = 'comics/comic'$_COMIC["id"] .'.png'
    image now equals 'comics/comic1.png'
    PHP Code:
    $_COMIC["title"] = "php script error: comic title not working."
    setting the title
    PHP Code:
    $_COMIC["name"] = "Comic #"$_COMIC["id"] ." "$_COMIC["title"] ."- Megaman Generations"
    name now equals 'Comic #1 php script error: comic title not working'
    PHP Code:
     if ($_COMIC["id"] == "1")
      {
    $_COMIC["title"] = "The Beggining";} 
    The id does equal 1, so title gets set to be 'The beggining'[sic]
    PHP Code:
    ... 
    PHP Code:
    <tr class="header"><td><center><b><?=$_COMIC["name"]?></b></center></td></tr>
    here, name (which is still 'Comic #1 php script error: comic title not working' as it hasn't been changed) is echo'd inside a table cell
    PHP Code:
    <tr bgcolor="#6495ED"><td><center><img src=<?=$_COMIC["image"]?> alt="No comic"></center></td></tr>
    </table>
    and then 'image' ( 'comics/comic1.png') gets echo'd as the source of your img tag.


    right, as I was typing I think I worked out your problem. You're thinking that the reference to title used when setting name will get updated when you change title. It won't. Concatenation of strings results in a new string, it is a literal value, and change to variables that were used in its composition will have no effect. (emphasis added to appropriate bits)

  • #6
    New Coder
    Join Date
    Feb 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    So I assemble $_COMIC["name"] before the "if" function or should I change it to $comic_name? Will the variables used to assemble the title change if it isn't magic?
    Last edited by megajosh2; 08-23-2006 at 09:41 PM.

  • #7
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    you probably want:

    PHP Code:
    $_COMIC["id"] = "1";
    $_COMIC["image"] = 'comics/comic'$_COMIC["id"] .'.png';
    $_COMIC["title"] = "php script error: comic title not working.";
     if (
    $_COMIC["id"] == "1")
      {
    $_COMIC["title"] = "The Beggining";}
    $_COMIC["name"] = "Comic #"$_COMIC["id"] ." "$_COMIC["title"] ."- Megaman Generations"

  • #8
    New Coder
    Join Date
    Feb 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ahh. Okay. I'll tell back how that works. (I learned an important lesson )

    Edit: IT worked!! Your awesome!!

  • #9
    New Coder
    Join Date
    Feb 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    2 questions.

    1. Can onClick be used for a php function?
    2. Can you send a form to "get" if the variable is a magic variable?

  • #10
    New Coder
    Join Date
    Feb 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It looks like typing ?comic_id=# doesn't change $comic_id to # when # is a number.

  • #11
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    1. No
    2. Your $_COMIC variable isn't magical.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #12
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    2. Your $_COMIC variable isn't magical.
    not sure why, but I laughed at that

  • #13
    New Coder
    Join Date
    Feb 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Can someone help me here? adding ?comic_id=# to the url doesn't change $comic_id. Does anyone know why? Do I need a $_GET? What I mean is http://mmgenerations.awardspace.com/...php?comic_id=# won't change $comic_id to #.
    Last edited by megajosh2; 08-24-2006 at 08:52 PM.

  • #14
    New Coder
    Join Date
    Feb 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Never mind. I solved it.

    PHP Code:
    $comic_id $_GET["comic_id"
    I'm a n00blet forgive me.


  •  

    Posting Permissions

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