   PHP MySQL help
  How can I have PHP and HTML code combined in a MySQL database?So like in table "wecContent", I have:?php include("http://localhost/wec/forums/ssi.php?a=active");include("http://localhost/wec/forums/ssi.php?a=stats"); ?>HELLO! Then do this on the actual page:When I try it, I guess it just doesn't read the PHP code inside the database. It works when it's not in the database.Tell me if you don't understand my question.   Elben"Give a man a fish and he will eat for a day. Teach a man how to fish and he will eat for a life time."-Chinese ProverbWiseElben.com - Experience Wisdom[edited by - WiseElben on February 3, 2004 8:05:06 PM]
  I think it''s safe to say that no one understands the question. ;  you probably want to be posting this in General Programming ;  WiseElben - You might need to do an eval() on the code when you get it from the DB.Eg: $whatever = mysql_query("SELECT theCode FROM `whatever`");eval($whatever);Edit: Just wanted to point out that this is pretty dodgy anyway; can you REALLY trust code from the database? Perhaps design revision time? www.coldcity.comcode, pics, life   [edited by - IainC on February 4, 2004 5:05:12 AM];  include("http://localhost/wec/forums/ssi.php?a=stats"); ?>The a=active is redundent (i think) because the ssi.php is included before it is parsed. In any case you should include using the local path, its a security thing. ;  Try to replace echo with printf(<the mysql stuff>);It might work. ;  I understand. But I hate to say that it cannot be done. Not this easily anyway. When you execute a PHP script, the source file is compiled into bytecode (or something) and then executed. You cannot simply add some extra PHP code in it. What you could try however is something like this. It's a bit cluncy but it should work:in your main pageif($_REQUEST['codeload']=="done"){  include("temp.php);}else{  $leftNav = mysql_query("SELECT data FROM `wecContent` WHERE 1");  $file = open("temp.php");  print $leftnav, $file;  close($file);  header("location: mainpage.php?codeload=done");}I am not sure what the exact open, print and close functions are, but the basic idea is that you dump the $leftnav in a temp file, reload the page (forcing the php to recompile and include your newly created temp.php file) and execute the PHP code from the database.As I said, cluncky, but workable.EDIT: Seems like eval($leftnav); would work as well, although it probabely needs to be:$leftnav = "<php ".$leftnav." ?>";eval($leftnav);Sander Maréchal[Lone Wolves Game Development][RoboBlast][Articles][GD Emporium][Webdesign][E-mail] [edited by - sander on February 4, 2004 5:20:05 AM];  Of course if more than one person acesses the webpage at one time... serious fuxx0r ;  I think you can ignore most of Sander's reply and simply replace this:echo mysql_result( $leftNav, 0 );with this:eval( mysql_result( $leftNav, 0 ) );I haven't tested this, in fact I hadn't even heard of eval() until reading Sander's reply. But most scripts do have such a command.   To clarify: Use your original code exactly as it is, just with the replacement mentioned above.EDIT: Oh, IainC answered this already.~CGameProgrammer( ); -- Post screenshots of your projects. 100+ posts already in the archives.[edited by - CGameProgrammer on February 4, 2004 8:15:45 AM];  Hey! I said it was cluncky! Anyway, After going over eval() at php.net, replace CGameProgrammers suggestion:eval( mysql_result( $leftNav, 0 ) );  with:eval( "<?php ".mysql_result( $leftNav, 0 )." ?>" );  It seems that eval() needs the PHP code tags...EDIT: Never mind me. OP's original MySql result already has the PHP code tags n it...  Sander Maréchal[Lone Wolves Game Development][RoboBlast][Articles][GD Emporium][Webdesign][E-mail] [edited by - sander on February 4, 2004 9:13:47 AM]