Jump to content


Photo

Insert PHP into page


  • Please log in to reply
8 replies to this topic

#1 me1000

me1000
  • Members
  • PipPipPip
  • Advanced Member
  • 183 posts

Posted 14 March 2006 - 01:41 AM

Ok ive got my database driven web site Im using

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

<?= $_CONTENT['PAGE_CONTENT'] ?>
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,

#2 keeB

keeB
  • Staff Alumni
  • Advanced Member
  • 1,078 posts
  • LocationCalifornia

Posted 14 March 2006 - 03:12 AM

I am not sure quite what you're asking..

Come visit my site to see my latest projects
http://nick.stinemates.org/wordpress/


#3 me1000

me1000
  • Members
  • PipPipPip
  • Advanced Member
  • 183 posts

Posted 14 March 2006 - 03:25 AM

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

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.


#4 kamiza

kamiza
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 14 March 2006 - 03:47 AM

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

<?
$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>";
?>


#5 me1000

me1000
  • Members
  • PipPipPip
  • Advanced Member
  • 183 posts

Posted 14 March 2006 - 10:02 PM

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)



#6 keeB

keeB
  • Staff Alumni
  • Advanced Member
  • 1,078 posts
  • LocationCalifornia

Posted 14 March 2006 - 10:07 PM

[!--quoteo(post=355084:date=Mar 14 2006, 10:02 PM:name=me1000)--][div class=\'quotetop\']QUOTE(me1000 @ Mar 14 2006, 10:02 PM) View Post[/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?

Come visit my site to see my latest projects
http://nick.stinemates.org/wordpress/


#7 me1000

me1000
  • Members
  • PipPipPip
  • Advanced Member
  • 183 posts

Posted 14 March 2006 - 11:37 PM

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.
<?= 

<?
echo = "Hello world"; 
?>

?>

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.

<?= 

echo = "Hello world"; 

?>

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

I hope someone is able to help me.

#8 keeB

keeB
  • Staff Alumni
  • Advanced Member
  • 1,078 posts
  • LocationCalifornia

Posted 15 March 2006 - 07:47 AM

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 [=

Come visit my site to see my latest projects
http://nick.stinemates.org/wordpress/


#9 me1000

me1000
  • Members
  • PipPipPip
  • Advanced Member
  • 183 posts

Posted 16 March 2006 - 01:47 AM

well i know its posible to execute a php function it. is there a way i can recode the page content output to make this posible?
as I realy need to be able to do this.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users