Jump to content

PHP/MYSQL changing pages instead of using diffrent php files

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
9 replies to this topic

#1
killcode

killcode

    Learning Programmer

  • Members
  • PipPipPip
  • 96 posts
Hello, i am trying to figure out a way to try and load diffrent content from a mysql database, but instead of making diffrent .php files and loading them individualy, i want it to load with the same file, but load diffrent content from the mysql database, how would i be able to do that?
Posted Image

#2
Guest_Jordan_*

Guest_Jordan_*
  • Guests
Pass a value to your script like "action". Based on the action value, you could pull different data from MySQL.

IE:
yoururl.com/index.php?action=loadData

#3
killcode

killcode

    Learning Programmer

  • Members
  • PipPipPip
  • 96 posts
I'm assuming you would use $_GET but how would i do it/check it like..

if ($_GET['action'] == 'something')
// then fetch data from mysql database blah blah blaah?
Posted Image

#4
Guest_Jordan_*

Guest_Jordan_*
  • Guests
Yup. In most instances I've seen a switch/case statement works better rather than multiple if statements.

#5
BlaineSch

BlaineSch

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,448 posts
or you could make the table look like "id, name, data"

page.php?name=contact
$name = $_GET['name'];
$query = mysql_query("SELECT id,name,data FROM content WHERE `name`='$name'");


#6
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
just make sure to protect for SQL injection, do
$name = mysql_real_escape_string($_GET['name']);

__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall

#7
BlaineSch

BlaineSch

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,448 posts
Don't tell him that, everybody should learn the hard way. That's where I come in Posted Image

#8
killcode

killcode

    Learning Programmer

  • Members
  • PipPipPip
  • 96 posts
Oh ok cool, thanks :D, im just wondering, how would i like...say i try to make a link (<a href="blah.php">blah blah</a>) then use $_GET by using "action"... im assumming that you need to add a HTML form?
Posted Image

#9
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
Not necesarily, you can do it by a link too!

<a href="blah.php?var=value&var2=value3">

sends those values to the $_GET in next page...
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall

#10
killcode

killcode

    Learning Programmer

  • Members
  • PipPipPip
  • 96 posts
oh cool! thanks !
Posted Image