• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

Needing PHP Help

Rindiny

Fwee!!!^^
  • 74
    Posts
    17
    Years
    • Age 33
    • Seen Sep 5, 2010
    Hello, I'm requiring some PHP help on a small project I'm working on. I'm basically writing up a mini-pokedex script for a friend.


    Code:
    <html>
    <head>
    
    <title>MiniDex - <?php echo("$pokemon"); ?></title>
    </head>
    <body>
    <?
    $pokemon = "Bulbasaur";
    ?>
    </body>
    </html>

    What's my problem? I declared the variable in my PHP script, but strangely it won't show up in my title. How do I fix this?
     

    Rindiny

    Fwee!!!^^
  • 74
    Posts
    17
    Years
    • Age 33
    • Seen Sep 5, 2010
    I removed the quotation marks that were in the <title> tag, and it didn't work.
     

    Rindiny

    Fwee!!!^^
  • 74
    Posts
    17
    Years
    • Age 33
    • Seen Sep 5, 2010
    Alright, I finally got it to work. Thanks Tyler!

    EDIT: I'm planning to use the ?page= script that Koroku has posted. How can I edit the values of $pokemon to match the variable declared to find the page?
     
  • 2,316
    Posts
    20
    Years
    I don't exactly get what you mean.
    What exactly do you want?

    Do you want ?pokemon=pokemonname to look for the Pokémon page or something?

    Would you mind posting the script here?
    I can't find it anymore...
     

    Rindiny

    Fwee!!!^^
  • 74
    Posts
    17
    Years
    • Age 33
    • Seen Sep 5, 2010
    Code:
    <?
    //Declare Main PHP Variables
    $news = "main.txt";
    $error = "404.txt";
    $ext = ".txt";
    //Include Variables
    if(!isset($_GET['pokemon'])){
    include $news;
    }
    elseif($_GET['page'] == "main") {
    include $news;
    }
    elseif(isset($_GET['pokemon']) && file_exists($_GET['pokemon'].$ext)){
    include $_GET['pokemon'].$ext;
    }
    else{
    include $error;
    }  
    ?>

    Example:
    ?pokemon=deoxys

    Title:

    Minidex - Deoxys

    How can I make it so by default the variable $pokemon turns into the page the user is currently on without me having to declare this option all the time?
     

    Rindiny

    Fwee!!!^^
  • 74
    Posts
    17
    Years
    • Age 33
    • Seen Sep 5, 2010
    I'm declaring $001 as a variable, and suddenly, it gives me a PHP error about declaring a variable as a number.
     

    Rindiny

    Fwee!!!^^
  • 74
    Posts
    17
    Years
    • Age 33
    • Seen Sep 5, 2010
    I'm declaring 001 as a variable because it's a Pokemon. What do you mean number itself? Do you mean "1" instead?
     
  • 2,316
    Posts
    20
    Years
    Yeah.
    If something is dependent from that number, simply use the number.
    If you want Bulbasaur, check whether the number is 1.

    I don't exactly know how your code us gonna look, so I can't say more.
     

    aRedMoon

    Wait for me outside the lines
  • 11,127
    Posts
    20
    Years
    Example:
    ?pokemon=deoxys

    Title:

    Minidex - Deoxys

    How can I make it so by default the variable $pokemon turns into the page the user is currently on without me having to declare this option all the time?
    The code isn't right.
    Code:
    <?
    //Declare Main PHP Variables
    $news = "main.txt";
    $error = "404.txt";
    $ext = ".txt";
    //Include Variables
    if(!isset($_GET['pokemon'])){
    include $news;
    }
    elseif($_GET['pokemon'] == "main") {
    include $news;
    }
    elseif(isset($_GET['pokemon']) && file_exists($_GET['pokemon'].$ext)){
    include $_GET['pokemon'].$ext;
    }
    else{
    include $error;
    }  
    ?>
    You forgot one.

    Stick that in index.php and going to index.php?pokemon=bulbasaur will load bulbasaur.txt

    If you want to have it print out the Pokemon, then you can do something like this: (Not the most secure, as I'm too lazy to deal with that right now)
    Code:
    <?
    $pokemon = $_GET['pokemon'];
    ?>
    Then whenever you want to print the name,
    Code:
    <? print "$pokemon"; ?>

    So when you go index.php?pokmeon=bulbasaur

    And have $pokemon somewhere in your code, it'll print out "bulbasaur"


    (And really, the best way to do a PokeDex would be to make it MySQL based, and work that way.)
     

    Rindiny

    Fwee!!!^^
  • 74
    Posts
    17
    Years
    • Age 33
    • Seen Sep 5, 2010
    I don't know any mySQL. It looks complicated. I don't know how to export data from a mySQL database into PHP code. What I mean is, if I add a piece of data saying something, say "Pikachu". I don't know how to print out the mySQL data the right way using PHP.
     

    aRedMoon

    Wait for me outside the lines
  • 11,127
    Posts
    20
    Years
    I've tried building a text file based PokeDex, and it's not fun at all.

    And there are a lot of tutorials out there~
     

    Rindiny

    Fwee!!!^^
  • 74
    Posts
    17
    Years
    • Age 33
    • Seen Sep 5, 2010
    I'm using variables for almost everything I can think of. The Pokedex was supposed to made up entirely of variables. So if I change a thing, it changes in all instead of one.
     

    aRedMoon

    Wait for me outside the lines
  • 11,127
    Posts
    20
    Years
    And what happens when you want to add something?

    With mySQL, it's maybe... 2 minutes? Flatfile... you're talking about editing 400+?
     
    Back
    Top