PDA

View Full Version : tinyMCE



philsbury
June 29th, 2007, 01:02 PM
Hi,

This is kind of PHP, but the plugin is Javascript so added it here too!

I am trying to create an external image list using TinyMCE. My code is as follows:


<script language="javascript" type="text/javascript" >
var tinyMCEImageList = new Array(
// Name, URL

);
</script>
<?
$trenn = ",";
echo 'var tinyMCEImageList = new Array(
';
include "library/config.php";
include "library/opendb.php";

$query = "SELECT id, title, name, type, size, content FROM images";
$result = mysql_query($query) or die('Error, query failed');
if ($result)
{
while ($r = mysql_fetch_array($result))

{
$link = $r["id"];
$name = $r["title"];
echo '["'.$name.'", "viewimage.php?id='.$link.'"]';
echo $trenn;
}
}
echo "","";
echo ');';

include 'library/closedb.php';
exit;



?>

This creates an array as follows:
var tinyMCEImageList = new Array( ["a title", "viewimage.php?id=5"],["wallpaper 5", "viewimage.php?id=6"],["vvbksdvbjkdfb", "viewimage.php?id=7"],);

But when I open the add image bit no menu displays. There is a comma after the last file which i think might be the problem, but can't seem to get rid of it.

If anyone can help it would be great!

Thanks
Phil

BetaWar
July 1st, 2007, 02:59 AM
If the comma is your problem then here is the type of modification that you would need to do:


<script language="javascript" type="text/javascript" >
var tinyMCEImageList = new Array(
// Name, URL

);
</script>
<?
$trenn = ",";
$loop = 0;
echo 'var tinyMCEImageList = new Array(
';
include "library/config.php";
include "library/opendb.php";

$query = "SELECT id, title, name, type, size, content FROM images";
$result = mysql_query($query) or die('Error, query failed');
if ($result)
{
while ($r = mysql_fetch_array($result))

{
if($loop>=1){
echo $trenn;
}
$loop++;
$link = $r["id"];
$name = $r["title"];
echo '["'.$name.'", "viewimage.php?id='.$link.'"]';

}
}
echo "","";
echo ');';

include 'library/closedb.php';
exit;



?>

That will post the comma at the beginning of the array values, but only after the first loop through the while loop has been made.