Jump to content

[SOLVED] Is this possible ?


Rommeo

Recommended Posts

Hi

As I am a newbie, there is something that i dont understand.

My question is :

 

i have a mysql table which keeps the data of the pages like "about us" & "contact" etc.

for to enter contact, i type :

"www.mywebsite.com/page.php?id=contact" 

 

and i have a page which looks for the data by the while loop named ad "photos.php"

for to see photos, i type

"www.mywebsite.com/photos.php"

 

And my question is ..

What if i write the "while-loop-code" in my mysql table, would it work ? when i enter ;

"www.mywebsite.com/page.php?id=photos"

 

As i said my photos.php file is just a mysql query which shows all the photos. I wanna save that code in my mysql.. But i m not sure whether that works. Is it possible ? Is there anyway to do that ?

 

I ll be glad if anyone can help.

Thanx in advance.

Link to comment
https://forums.phpfreaks.com/topic/123598-solved-is-this-possible/
Share on other sites

page.php?id=x

The value of x is probably used to lookup the row containing the content for the page from a database table

photos.php is a completely different file and must have code to get images from a different database table

 

"www.mywebsite.com/page.php?id=photos"

Will not work

 

To save the php code into a mysql field will require php knowledge and modification of the code in page.php to tell it to expect code when id=photos

 

 

Yes ,but it is not a good idea, here is one way to do it

 

index.php?page=photos

<?php
if(isset($_GET['page']))
{
$page = $_GET['page'];
require_once '$page.php';
}
?>

Not very secure, but it will start you off, or if you want to do it your way

 

You will have a table called content

 

then two rows, one called title and one called content (which will be text, not varchar)

 

Then do

<?php
if(isset($_GET['page']))
{
$page = $_GET['page'];
$page = mysql_real_escape_string($page);
//assuming you are connected to the database
$sql = "SELECT*FROM content WHERE title='$page'";
$query = mysql_query($sql);
while($rows = mysql_fetch_assoc($query))
{
echo $rows['content'];
}
}
?>

 

That should start you off.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.