Jump to content

Insert PHP into page


me1000

Recommended Posts

Ok ive got my database driven web site Im using
[code]

        $query = "SELECT * FROM $sTableName WHERE ID=$inPageID LIMIT 1";
    $_CONTENT = mysql_fetch_array(mysql_query($query));

<?= $_CONTENT['PAGE_CONTENT'] ?>
[/code]
to insert the content, into the page.

Now if I wanted to add a php command into the page (the part thats stored on the database) im not sure what to do.

can someone help me out here?

Thanks,
Link to comment
https://forums.phpfreaks.com/topic/4894-insert-php-into-page/
Share on other sites

ok say you wanted to do an include
[code]
<?
include("somepage.php");
?>[/code]

well if a add that code to the page, then it comes out as nothing at all.
but if you get rid of the <? ?> tags then it comes out include("somepage.php"); on the page.
its the same way with every command.
Link to comment
https://forums.phpfreaks.com/topic/4894-insert-php-into-page/#findComment-17242
Share on other sites

No no, he wants to retrieve something from a mysql database, and then display it

right now all you need to do is

<? echo "$_CONTENT"; ?>

and actually just use $Content, dont need underscore

--
but if want like organized do something like this

[code]
<?
$query = "SELECT * FROM tablename ORDER BY id";
$result = mysql_query($query);
// Same as you have but don't do the fetch_array yet

while($c = mysql_fetch_array($result))
{
echo "$c[username] <br>";
echo "$c[message] <br>";
echo "$c[date] <br>";
?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/4894-insert-php-into-page/#findComment-17245
Share on other sites

no the page works fine, with standard HTML. the site is already up a running off of a mysql database. I just gave you some sample code. im using the _ for easier viewing (by myself).

im trying to display a page from the database which works fine with standard HTML. but If I want to add php to the page (the page being stored in the database) it comes out with wierd results (as shown below)

Link to comment
https://forums.phpfreaks.com/topic/4894-insert-php-into-page/#findComment-17554
Share on other sites

[!--quoteo(post=355084:date=Mar 14 2006, 10:02 PM:name=me1000)--][div class=\'quotetop\']QUOTE(me1000 @ Mar 14 2006, 10:02 PM) [snapback]355084[/snapback][/div][div class=\'quotemain\'][!--quotec--]
no the page works fine, with standard HTML. the site is already up a running off of a mysql database. I just gave you some sample code. im using the _ for easier viewing (by myself).

im trying to display a page from the database which works fine with standard HTML. but If I want to add php to the page (the page being stored in the database) it comes out with wierd results (as shown below)
[/quote]

So inside of your database cell you have PHP code that you want to be interpreted?

I've never done that before, nor can I see any reason why you would want to.. Would you like to explain what exactly you're trying to accomplish?
Link to comment
https://forums.phpfreaks.com/topic/4894-insert-php-into-page/#findComment-17559
Share on other sites

Exactly!

well there are a few things I would like to do,
but I wiould like to make a random page generator. this would need to be php driven because it would need to grab a random page from the database. and since im am added pages all the time, I dont want to add a line to a JS every time I add a page. there are several random things I would like to do. ive bee trying to see how the server would inturprate it and send it to the browser.

and tyhis is what ive come up with.
[code]<?=

<?
echo = "Hello world";
?>

?>
[/code]

with this I can see that there are extra php tags (<? ?>) (when I test this out it shows nothing at all)

so i try this.

[code]
<?=

echo = "Hello world";

?>
[/code]

This shows "echo = "Hellow world";" on the page its not inturpreted as saying "hello world".

I hope someone is able to help me.
Link to comment
https://forums.phpfreaks.com/topic/4894-insert-php-into-page/#findComment-17600
Share on other sites

the problem is.. to 'output' the results.. you're PRINT or ECHO'ing them..

which.. of course, you're just printing a string and it's not interpreted..

if you want to pull a random page from the db, there's much easier ways..

Make the pages in .php format.. and generate a random number between 1 and SELECT COUNT(*) from TABLENAME .. the tableName will contain the FILENAME of a local .PHP file.. which in your GENERATERANDOMPAGE.php.. it will include($randomFileName); from the DB. :)

If you need help implimenting that, just ask [=
Link to comment
https://forums.phpfreaks.com/topic/4894-insert-php-into-page/#findComment-17724
Share on other sites

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.