glenelkins Posted November 11, 2006 Share Posted November 11, 2006 Better to my last post, how do I execute a php script from within another without include() i dont want to display the output or have the file included Quote Link to comment https://forums.phpfreaks.com/topic/26930-resolved-executing-scripts-without-include-function/ Share on other sites More sharing options...
shocker-z Posted November 11, 2006 Share Posted November 11, 2006 you could look into running PHP on the command line and using exec(); to execut it..y not, not output anything on the page as u mustn't anyway otherwise they would need to see the page.. and just use include()?http://us2.php.net/features.commandlineRegardsLiam Quote Link to comment https://forums.phpfreaks.com/topic/26930-resolved-executing-scripts-without-include-function/#findComment-123165 Share on other sites More sharing options...
glenelkins Posted November 11, 2006 Author Share Posted November 11, 2006 HiNo the include function included the file so the code can run and generate content for the variable $content. Due to this being in a loop and using a different included file for each iteration of the loopexample of what i mean[code]while (something) { include ("something.php"); // Sets up the variable $content (different file each time) echo $content;}[/code];but with this loop the last included file still is included and runs through again after the next include and messes up the display Quote Link to comment https://forums.phpfreaks.com/topic/26930-resolved-executing-scripts-without-include-function/#findComment-123181 Share on other sites More sharing options...
wildteen88 Posted November 11, 2006 Share Posted November 11, 2006 Take the echo statement out side of the while loop then. Everytime the while loop loops its going to echo the $content variable each time. If you stick it out side of the while loop it'll echo the $content variable when its finished looping the while loop. Quote Link to comment https://forums.phpfreaks.com/topic/26930-resolved-executing-scripts-without-include-function/#findComment-123187 Share on other sites More sharing options...
glenelkins Posted November 11, 2006 Author Share Posted November 11, 2006 aloright your not getting what im trying to sayi am writing a cms script and i have written a function to display the blocks down the left and right. One of the options is if the block content is a file or from the database. Simply due to some blocks needing PHP code. So i write these scripts to generate the block content into $content by including it for each block in the loop if needed. Ech time the loop included as document for the block (filename in database) the file is included but due to the page not refreshing (looping) it keeps including each document one after the other and the $content stays the same as the first file becomes the last in the script.I need to take the $content variable from each script and add to an array, but i cant unless i can run the code without including it...do you get what i mean? Quote Link to comment https://forums.phpfreaks.com/topic/26930-resolved-executing-scripts-without-include-function/#findComment-123198 Share on other sites More sharing options...
glenelkins Posted November 11, 2006 Author Share Posted November 11, 2006 - Quote Link to comment https://forums.phpfreaks.com/topic/26930-resolved-executing-scripts-without-include-function/#findComment-123227 Share on other sites More sharing options...
glenelkins Posted November 11, 2006 Author Share Posted November 11, 2006 So i assume no1 knows how to solve this? there must be a way to read one php files code and run it inside another without include() Quote Link to comment https://forums.phpfreaks.com/topic/26930-resolved-executing-scripts-without-include-function/#findComment-123233 Share on other sites More sharing options...
shocker-z Posted November 11, 2006 Share Posted November 11, 2006 do you have a link to what is happening? then we may be able to see what you mean as im not understanding you fully.RegardsLiam Quote Link to comment https://forums.phpfreaks.com/topic/26930-resolved-executing-scripts-without-include-function/#findComment-123234 Share on other sites More sharing options...
glenelkins Posted November 11, 2006 Author Share Posted November 11, 2006 Right, i have a table called "blocks" the blocks table has fields "tittle,position,content". The position is Left or RIght of the screen. No the script loops through all the records in the blocks table with the position, so say we want to generate the left boxes we use "SELECT * FROM blocks WHERE position='Left'" We then loop through and create each block using a template HTML file with {title} and {content} tags. Thats fine!. But some of the blocks use a php file to generate their content, so in the loop i want to be able to run the code in the content php files with each of them setting $content variable with the output. When I include the php files that create the $content for each block it only works for the first iteration as each time a file is included in the loop it goes through them all and only the last bit of code which sets $content is found.[code] function GenerateBlocks ($position,$template) { $result = $this->DbQuery ("SELECT * FROM blocks WHERE position='$position'") or die (mysql_error()); while ($blocks = mysql_fetch_array($result)) { if ($blocks['active'] == '1') { echo $blocks['title'] . "<br>"; if ($blocks['admin'] == '1' && $_SESSION['level'] == '1' or $blocks['admin'] == '0') { if ($blocks['members'] == '0' xor $blocks['members'] == '1' && $_SESSION['logged'] == 'yes') { if ($blocks['file'] == '1') { require_once (BLOCKS_FOLDER . $blocks['filename']); $content = array($blocks['title'],$content); } else { $content = array($blocks['title'],$blocks['content']); } $tags = array("{title}","{content}"); $block .= $this->GenerateContent($tags,$content,$template,"block.html"); } } } } return $block; }[/code] Quote Link to comment https://forums.phpfreaks.com/topic/26930-resolved-executing-scripts-without-include-function/#findComment-123245 Share on other sites More sharing options...
glenelkins Posted November 12, 2006 Author Share Posted November 12, 2006 - Quote Link to comment https://forums.phpfreaks.com/topic/26930-resolved-executing-scripts-without-include-function/#findComment-123463 Share on other sites More sharing options...
glenelkins Posted November 12, 2006 Author Share Posted November 12, 2006 problem solved, i just created a new object in each loop iteration! Quote Link to comment https://forums.phpfreaks.com/topic/26930-resolved-executing-scripts-without-include-function/#findComment-123501 Share on other sites More sharing options...
trq Posted November 12, 2006 Share Posted November 12, 2006 Good. Please mark the thread accordingly next time. Quote Link to comment https://forums.phpfreaks.com/topic/26930-resolved-executing-scripts-without-include-function/#findComment-123505 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.