/    Sign up×
Community /Pin to ProfileBookmark

include without display the echo’d data

Hi,

Sorry it the title is a little confussing.

I am using the tinymce and I am generating the image_list in a php file. My system has all the variables declared for my database and tbl names etc. Obviously when the tinymce references the list it will run the php code within the page and display what I get to echo out.

[code=php]
function GetImages($Purpose) {

$imagestr = “”;

$sql = “SELECT * FROM ” . TBL_IMAGES . ” WHERE GalleryID=’0′ AND Active=’1′ AND IMGPurpose='” . $Purpose . “‘”;

$queryresults = mysqlquery($sql, “image_list.php”, “GetImages”, __LINE__);

// Run through all the images and place into a string to return
while ($results = mysqlarray($queryresults, “image_list.php”, “GetImages”, __LINE__, $sql, true)) {
$imagestr .= ‘[“‘ . $results[“IMGName”] . ‘”, “‘ . $results[“smlURL”] . ‘”],’;
}

// Remove the last comma
$imagestr = rtrim($imagestr, ‘,’);
return $imagestr;
}

$js = ‘var tinyMCEImageList = new Array(‘;
$js .= GetImages($_SESSION[“IMGPurpose”]);
// test
$js .= ‘[“aa”, “asdfsadf”]);’;
echo $js;
[/code]

As you can see from above it will run through my db and pull the images out.

The problem I have is for this function to work I need to somewhere include the file. When I do include the file it obviously displays the echo’d data.

Not sure on how to get around this?

Thanks
k0r54

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@MindzaiJan 18.2010 — Not sure I understand the problem, but it sounds like you need to rethink your code organization. Files which do things like provide a database connection or a set of functions shouldn't be echoing anything.
Copy linkTweet thisAlerts:
@HeeLJan 18.2010 — Look for functions: ob_start and ob_end
Copy linkTweet thisAlerts:
@MindzaiJan 18.2010 — ^^^

That's a very hacky method which doesn't address the actual problem imo. Output buffering as a means of fixing problems caused by bad organization isn't a good idea. It's better to fix the problem itself.
Copy linkTweet thisAlerts:
@JerailJan 18.2010 — Instead of actually echoing everything, maybe you should record the output in a global array/variable that you could then output at the proper place in your script. so instead of echoing $js at the end, you could just do[code=php]$_SESSION['js'] = $js;[/code].

Not entirely sure what you're trying to do, though.
Copy linkTweet thisAlerts:
@k0r54authorJan 19.2010 — Hi,

Yes that is exactly what I have done.

Basicly tinyMCE (wysiwyg) allows you to select images. However the file it looks at is a js file which contains an array in javascript to tell them gui what images are in there. I wanted to create a php script so I could pull the images and locations from a database. Obviously because it was javascript that was calling it, it was expecting a js output when the file is reference. I ended up adding $_GET variable to tell my script where it was being called from.

That way I was able to put into a session variable the results from the sql query.

Thanks for you help though
×

Success!

Help @k0r54 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.3,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...