Forum Moderators: coopster

Message Too Old, No Replies

Running php include files from sql data

         

cheaperholidays

10:51 pm on Aug 5, 2009 (gmt 0)

10+ Year Member



Hi
We have all our travel resort guides in an sql database administered with phpmyadmin

However i need for example to add weather data from a php include file, how can i add this via phpmyadmin <?php include ect> and have it fire when the page is selected.

Thanls for reading

Kev

eelixduppy

11:41 pm on Aug 5, 2009 (gmt 0)



I'm not sure I understand what you are looking for here. Can you please elaborate on your problem so we can best help you with your problem.

cheaperholidays

5:57 am on Aug 6, 2009 (gmt 0)

10+ Year Member



Hi

We have all our data for the resort guides in a database however i want to edit the file for say Corfu and add a php include to the database in the form of

<?php include();?> however when i do that it just adds <?php include();?> as if it was just text, and does not include the file content if that makes sense.

Kev

eelixduppy

1:14 am on Aug 7, 2009 (gmt 0)



Oh, I understand you now. You have to actually include the content as a string, include does not return a string in the sense that you think. For that you are going to have to use file_get_contents [php.net]().

idfer

4:17 am on Aug 7, 2009 (gmt 0)

10+ Year Member



I'm guessing right now there's a script that reads the data from the database and echo's it directly to the browser? If your data contains PHP code you need to eval() it instead of echoing it, so that the PHP code is parsed.

But you need to be a bit careful if you have plain HTML mixed with the <?php include ?> statements, then you want to wrap the data in closing and opening php tags. So let's say your existing script does something like this:

$qh = mysql_query('select page_content from pages ...');
$row = mysql_fetch_array($qh);
echo $row['page_content'];

You want to change it to:

$qh = mysql_query('select page_content from pages ...');
$row = mysql_fetch_array($qh);
eval ('?>'.$row['page_content'].'<?php');

(You don't really need the opening <?php tag at the end, but it's good form to put it there).

Just keep in mind that syntax errors inside eval'd code aren't reported, so it's a bit hard to work with. See [php.net...] for more info.

Hope this helps.

cheaperholidays

7:58 am on Aug 7, 2009 (gmt 0)

10+ Year Member



Hi idfer thanks for your help its much appreciated

This is the php code we have, this needs to amended however i have no idea, how to do that?

<?
$description = ereg_replace("\n","<br>",$destrow[2]);
print("$description");
?>

Please advise how can i amend this to eval the php we want to include.

Kev