PDA

View Full Version : Needing PHP Help


Rindiny
April 3rd, 2007, 08:09 PM
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.



<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?

Tyler
April 3rd, 2007, 08:23 PM
Because you dont put " " around your variable in the echo.

Rindiny
April 3rd, 2007, 08:26 PM
I removed the quotation marks that were in the <title> tag, and it didn't work.

Tyler
April 3rd, 2007, 08:29 PM
put the
<?
$pokemon = "Bulbasaur";
?>
above the <html>

Rindiny
April 3rd, 2007, 09:05 PM
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?

Virtual Headache
April 3rd, 2007, 09:12 PM
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
April 3rd, 2007, 09:42 PM
<?
//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?

Virtual Headache
April 3rd, 2007, 09:50 PM
Simply use

<?
echo '<title>'.$_GET['pokemon'].'</title>';
?>
for the title.

Rindiny
April 4th, 2007, 07:43 PM
I'm declaring $001 as a variable, and suddenly, it gives me a PHP error about declaring a variable as a number.

Virtual Headache
April 4th, 2007, 07:56 PM
Why do you need 001 as a variable anyway?
If you want to make something dependent from this value, why don't you just use the number itself?

Rindiny
April 4th, 2007, 08:00 PM
I'm declaring 001 as a variable because it's a Pokemon. What do you mean number itself? Do you mean "1" instead?

Virtual Headache
April 4th, 2007, 08:10 PM
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.

Koroku
April 5th, 2007, 12:26 AM
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.
<?
//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)<?
$pokemon = $_GET['pokemon'];
?>Then whenever you want to print the name,<? 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
April 5th, 2007, 03:43 PM
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.

Koroku
April 5th, 2007, 04:55 PM
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
April 5th, 2007, 06:06 PM
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.

Koroku
April 6th, 2007, 01:12 AM
And what happens when you want to add something?

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