Author Topic: PHP URL Variables  (Read 1966 times)

Ginger

  • Dev Team Member
  • Hero Member
  • *****
  • Posts: 610
  • Reputation: 6
    • PwnDevTeam!
  • Computers: Forgot model but Dell Inspirion Tower (6gb ram, Quad core, 1tb hdd, 1gb graphics)
  • iDevices: iPod Touch 4G 8GB And iPod Nano 1G 1Gb
PHP URL Variables
« on: November 19, 2011, 12:09:01 pm »
On some domains you like url's like
domain.com/index.php?page=bla

I've tried googling this but found nothing

Basically i have a template (index.php) and when some adds the ?page=blabla I would like it to data from a different Mysql table

Trcx528

  • Haxor
  • Hero Member
  • *****
  • Posts: 4502
  • Reputation: 166
  • Google it!
    • iNinjas
  • Badges:
  • Computers: 13" 2011 Macbook Pro, 120 GB SSD and 16 GB of Ram
  • iDevices: None
Re: PHP URL Variables
« Reply #1 on: November 19, 2011, 12:51:46 pm »

Ginger

  • Dev Team Member
  • Hero Member
  • *****
  • Posts: 610
  • Reputation: 6
    • PwnDevTeam!
  • Computers: Forgot model but Dell Inspirion Tower (6gb ram, Quad core, 1tb hdd, 1gb graphics)
  • iDevices: iPod Touch 4G 8GB And iPod Nano 1G 1Gb
Re: PHP URL Variables
« Reply #2 on: November 19, 2011, 03:33:38 pm »
Check this out: http://www.w3schools.com/php/php_get.asp
It's relervent to $Get but not for the different MySQL data :) But +1 :D

Trcx528

  • Haxor
  • Hero Member
  • *****
  • Posts: 4502
  • Reputation: 166
  • Google it!
    • iNinjas
  • Badges:
  • Computers: 13" 2011 Macbook Pro, 120 GB SSD and 16 GB of Ram
  • iDevices: None
Re: PHP URL Variables
« Reply #3 on: November 19, 2011, 03:40:20 pm »
Maybe it would help if I knew what you were asking
... adds the ?page=blabla I would like it to data from a different Mysql table
How exactly do you "data" from a different table?  lol, you used it as a verb, but it's a noun so I guessed at what you were asking.

Ginger

  • Dev Team Member
  • Hero Member
  • *****
  • Posts: 610
  • Reputation: 6
    • PwnDevTeam!
  • Computers: Forgot model but Dell Inspirion Tower (6gb ram, Quad core, 1tb hdd, 1gb graphics)
  • iDevices: iPod Touch 4G 8GB And iPod Nano 1G 1Gb
Re: PHP URL Variables
« Reply #4 on: November 19, 2011, 04:41:53 pm »
If ?page=lol Then I would like it to select specific MySQL data from the table lol :)

Don't like seeing ads? Click here to register!

A3MIRAL

  • Leader
  • Hero Member
  • *****
  • Posts: 2899
  • Reputation: 105
  • A3MIRAL -- Reporting for Duty
    • A3MIRAL
  • Badges:
  • Computers: Dell XPS15 (6 GB ram, Core i7 @ 2.0 GHz, 750 GB HDD @ 7200 RPM)
  • iDevices: iPod touch 3G 32GB, iPhone 5 32GB
Re: PHP URL Variables
« Reply #5 on: November 19, 2011, 04:45:34 pm »
ok...wait 20 mins.
ill have a nice detailed answer (if u ever need php help, ask me ;))

A3MIRAL

  • Leader
  • Hero Member
  • *****
  • Posts: 2899
  • Reputation: 105
  • A3MIRAL -- Reporting for Duty
    • A3MIRAL
  • Badges:
  • Computers: Dell XPS15 (6 GB ram, Core i7 @ 2.0 GHz, 750 GB HDD @ 7200 RPM)
  • iDevices: iPod touch 3G 32GB, iPhone 5 32GB
Re: PHP URL Variables
« Reply #6 on: November 19, 2011, 05:02:34 pm »
Code: (php) [Select]
<?
// This is how you get all variables from he url
// This is why descriptive names are important, as this takes all the names and assigns the values to the names

foreach ($_GET as $name => $value){
 $name = $value;
}

// MYSQL database connections
$connection = mysql_connect("server", "username", "password");

// select database
mysql_select_db("db_name", $connection);

// Create query
$query = "SELECT * from TABLENAME_HERE"

// Exectute query
$result = mysql_query($query);

// While there is data to be taken...
while ($row = mysql_fetch_array($result)){
 // If a certian variable from the get (url variable) is set, include a peice of mysql data
 if (isset($GET_VAR_NAME)){
  echo $row["MYSQL_DATA_ROW_NAME"];
 }
}
// add more isset() to add more possibilities

mysql_close($connection);

?>



A3MIRAL

  • Leader
  • Hero Member
  • *****
  • Posts: 2899
  • Reputation: 105
  • A3MIRAL -- Reporting for Duty
    • A3MIRAL
  • Badges:
  • Computers: Dell XPS15 (6 GB ram, Core i7 @ 2.0 GHz, 750 GB HDD @ 7200 RPM)
  • iDevices: iPod touch 3G 32GB, iPhone 5 32GB
Re: PHP URL Variables
« Reply #7 on: November 19, 2011, 05:04:11 pm »
obviously theres plenty of alternates, and this isnt 100% fool proof (more than one variable can be present, in which case you may want one data value to overrule..so add more if constructs!)

Ginger

  • Dev Team Member
  • Hero Member
  • *****
  • Posts: 610
  • Reputation: 6
    • PwnDevTeam!
  • Computers: Forgot model but Dell Inspirion Tower (6gb ram, Quad core, 1tb hdd, 1gb graphics)
  • iDevices: iPod Touch 4G 8GB And iPod Nano 1G 1Gb
Re: PHP URL Variables
« Reply #8 on: November 20, 2011, 02:45:30 am »
Wow thanks, but I don't get isset($GET_VAR_NAME

How can I choose what table :( I know I need to change MYSQL DATA ROW NAME but like

?page=lol

I need the MySQL data row name to be lol


A3MIRAL

  • Leader
  • Hero Member
  • *****
  • Posts: 2899
  • Reputation: 105
  • A3MIRAL -- Reporting for Duty
    • A3MIRAL
  • Badges:
  • Computers: Dell XPS15 (6 GB ram, Core i7 @ 2.0 GHz, 750 GB HDD @ 7200 RPM)
  • iDevices: iPod touch 3G 32GB, iPhone 5 32GB
Re: PHP URL Variables
« Reply #9 on: November 20, 2011, 08:12:33 am »
you should know what the mysql data you need to be echod when a certian url variable is set. thats how it works

Don't like seeing ads? Click here to register!

A3MIRAL

  • Leader
  • Hero Member
  • *****
  • Posts: 2899
  • Reputation: 105
  • A3MIRAL -- Reporting for Duty
    • A3MIRAL
  • Badges:
  • Computers: Dell XPS15 (6 GB ram, Core i7 @ 2.0 GHz, 750 GB HDD @ 7200 RPM)
  • iDevices: iPod touch 3G 32GB, iPhone 5 32GB
Re: PHP URL Variables
« Reply #10 on: November 20, 2011, 08:24:37 am »
oooo i see....

Code: [Select]
// is the get variable from earlier named page set?
if (isset($page)){
 // If so...echo that row
$query = "SELECT {$page} FROM table_name";
// variable value must coorispond to the data you want echo'd
}

// query
$result = mysql_querry($query);

// executes the query and echos it
echo $result;


and u can erase everything between the database connection and the close connection.


Ginger

  • Dev Team Member
  • Hero Member
  • *****
  • Posts: 610
  • Reputation: 6
    • PwnDevTeam!
  • Computers: Forgot model but Dell Inspirion Tower (6gb ram, Quad core, 1tb hdd, 1gb graphics)
  • iDevices: iPod Touch 4G 8GB And iPod Nano 1G 1Gb
Re: PHP URL Variables
« Reply #11 on: November 20, 2011, 08:58:36 am »
Thanks :)
😍❤ +1

Ginger

  • Dev Team Member
  • Hero Member
  • *****
  • Posts: 610
  • Reputation: 6
    • PwnDevTeam!
  • Computers: Forgot model but Dell Inspirion Tower (6gb ram, Quad core, 1tb hdd, 1gb graphics)
  • iDevices: iPod Touch 4G 8GB And iPod Nano 1G 1Gb
Re: PHP URL Variables
« Reply #12 on: November 23, 2011, 10:08:52 am »
Doesnt seem to be working :( I get no errors but when I go to .php?page=BLABLA
It doesn't show what's in the table :( and I've tried caps etc...

A3MIRAL

  • Leader
  • Hero Member
  • *****
  • Posts: 2899
  • Reputation: 105
  • A3MIRAL -- Reporting for Duty
    • A3MIRAL
  • Badges:
  • Computers: Dell XPS15 (6 GB ram, Core i7 @ 2.0 GHz, 750 GB HDD @ 7200 RPM)
  • iDevices: iPod touch 3G 32GB, iPhone 5 32GB
Re: PHP URL Variables
« Reply #13 on: November 23, 2011, 10:42:59 am »
give me a little while and ill hop on irc

Ginger

  • Dev Team Member
  • Hero Member
  • *****
  • Posts: 610
  • Reputation: 6
    • PwnDevTeam!
  • Computers: Forgot model but Dell Inspirion Tower (6gb ram, Quad core, 1tb hdd, 1gb graphics)
  • iDevices: iPod Touch 4G 8GB And iPod Nano 1G 1Gb
Re: PHP URL Variables
« Reply #14 on: November 23, 2011, 10:55:50 am »
Ok im on there now :D