• Welcome to Valhalla Legends Archive.
 

Help with PHP

Started by Dale, June 05, 2007, 07:06 PM

Previous topic - Next topic

Dale

Alright, I don't really know what to call this, so maybe that's why I can't find any tutorials online, but in PHP you know how most sites, atleast professional sites have index.php?id=1 or whatever, with the id, and such. How do I do this? Could someone post code? commented? tutorial? virtually anything is helpful!

Thanks.

Warrior

Look up $_GET on the PHP Website.
Quote from: effect on March 09, 2006, 11:52 PM
Islam is a steaming pile of fucking dog shit. Everything about it is flawed, anybody who believes in it is a terrorist, if you disagree with me, then im sorry your wrong.

Quote from: Rule on May 07, 2006, 01:30 PM
Why don't you stop being American and start acting like a decent human?

FrostWraith

#2
Since this took me a bit to figure out when I started, I'll give a simple example.
This is if you do index.php?page=X
<?php
     
    
if (isset($_GET['page'] ) )
    {
        
$page $_GET['page'];
    }
    else
    {
        
$page 0;
    }
     
    switch (
$page )
    {
         
        case 
1:
         
        echo 
"Contents of index.php?page=1";
        break;
         
        case 
2:
         
        echo 
"Contents of index.php?page=2";
        break;
         
        default: 
//OPTIONAL
         
        
echo "Contents of index.php?page=anythingelse";
        break;
    }
?>

rabbit

Almost, you should cast $_GET['page'] to int before you check it.
Grif: Yeah, and the people in the red states are mad because the people in the blue states are mean to them and want them to pay money for roads and schools instead of cool things like NASCAR and shotguns.  Also, there's something about ketchup in there.

Warrior

Assuming you're expecting an int :P
Quote from: effect on March 09, 2006, 11:52 PM
Islam is a steaming pile of fucking dog shit. Everything about it is flawed, anybody who believes in it is a terrorist, if you disagree with me, then im sorry your wrong.

Quote from: Rule on May 07, 2006, 01:30 PM
Why don't you stop being American and start acting like a decent human?

CrAzY

Warrior,

When ever you see Something=Value on the URL, this is simply saying $Something = value;

So if I were to have code that said


<?
echo("Your name is ".$name);
?>



And you made the URL say, http://yoursite.com/index.php?name=Warrior, you would get a page that says 'Your name is Warrior'.

Hope this helps!
CrAzY

rabbit

AHAHAHAHA!!!!

CrAzY, Warrior knows more PHP than you could ever hope to.  He was responding to me, because I said cast it to an int.  And he's right.  I use numbers for all of my page traversing, so I'm used to casting to int everything.
Grif: Yeah, and the people in the red states are mad because the people in the blue states are mean to them and want them to pay money for roads and schools instead of cool things like NASCAR and shotguns.  Also, there's something about ketchup in there.

warz