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?
PHP/MYSQL changing pages instead of using diffrent php files
Started by killcode, Oct 18 2009 02:51 PM
9 replies to this topic
#1
Posted 18 October 2009 - 02:51 PM
|
|
|
#2
Guest_Jordan_*
Posted 18 October 2009 - 03:08 PM
Guest_Jordan_*
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
IE:
yoururl.com/index.php?action=loadData
#3
Posted 18 October 2009 - 03:20 PM
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?
if ($_GET['action'] == 'something')
// then fetch data from mysql database blah blah blaah?
#4
Guest_Jordan_*
Posted 18 October 2009 - 03:50 PM
Guest_Jordan_*
Yup. In most instances I've seen a switch/case statement works better rather than multiple if statements.
#5
Posted 18 October 2009 - 05:04 PM
or you could make the table look like "id, name, data"
page.php?name=contact
page.php?name=contact
$name = $_GET['name'];
$query = mysql_query("SELECT id,name,data FROM content WHERE `name`='$name'");
#6
Posted 18 October 2009 - 06:41 PM
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
I study Information Systems at Karlstad University when I'm not on CodeCall
#7
Posted 18 October 2009 - 06:45 PM
Don't tell him that, everybody should learn the hard way. That's where I come in
#8
Posted 20 October 2009 - 08:39 AM
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?
#9
Posted 20 October 2009 - 09:18 AM
Not necesarily, you can do it by a link too!
sends those values to the $_GET in next page...
<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
I study Information Systems at Karlstad University when I'm not on CodeCall
#10
Posted 20 October 2009 - 09:40 AM


Sign In
Create Account


Back to top










