PDA

View Full Version : Newb PHP Question (function, method thingy)


Robbins
06-29-2006, 03:26 AM
Hey,

I want to make a simple php script that would show a bunch of diffrent things depending on the url. For example, if someone went to file.php?method=pictures it would show pictures, or whatever i tell it to. the problem with this, is that i need this file to be able to do that with MANY things, like with ?method=file1 ?method=somethingelse And i don't think the ifelse would do it. How can i do this, so that diffrent things like that would show diffrent things? Woud I have to use as many ifelse's as i needed diffrent categorys? Please give me some example code!! Thanks alot! :D

EDIT: I was just looking at these forums, and noticed where i have method, they have do for some stuff... how can i go about changing the method= to like game= once i get it working? Thanks to anyone that can post some code and help me out!!!!

boeing747fp
06-29-2006, 03:43 AM
are you familiar with $_GET[] variables at all?

if you want to detect a URL query string and include a separate file for each "method", you can do this

Make different files for each "method" and name them the "method" with a .php extension

<?php
$method = $_GET['method'];
if(!$method){
exit("No Method Chosen.");
}else{
$file = $method.".php";
include($file);
}
?>


or if you want to stay all in 1 page, you would need if/else statements

<?php
$method = $_GET['method'];
if($method == "something"){
//Do Something for this method
///////CODE HERE////////////
}elseif($method == "somethingelse"){
//Do Something for this method
///////CODE HERE////////////
}
//.....etc etc////
?>