Jump to content

[resolved] Executing Scripts Without Include() Function


glenelkins

Recommended Posts

Hi

No 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 loop

example 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
Link to comment
Share on other sites

aloright your not getting what im trying to say

i 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?
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.