Javascript-Code inside a PHP-Code

Search
Other Bug Reports questions
Forum

Javascript-Code inside a PHP-Code

Reiner Beckmann's Avatar Reiner Beckmann
I am using Jooma 4.2.5 with JCE 2.9.32, Sourcer 9.3. I want to pass a php query value from a database into a javascript using. And the script should trigger the result in the frontend. For this purpose, a line of Javascript is output within PHP. There seems to be a problem here, instead of the value, part of the code is output. The script works in an old Joomla installation (version 3, also with sourcer) or in a pure PHP file.
For the sake of completeness, it should be said that the article for the issue is in a module position.
Javascript:
<script type="text/javascript" language="javascript">
var i='0';
var index = 0;

function marqueeA(suchbegriff)
{
laenge = 0;
marquee1.value = "";
index = 0;
marquee(suchbegriff);
}

function marquee(suchbegriff)
{
laenge = suchbegriff.length;
laenge = laenge;
buchstaben = marquee1.value;
if (buchstaben.length < laenge)
  {
  var showString = '0';
  showString = suchbegriff;
  var stringLength= showString.length;
  marquee1.rows = laenge / 25+1;
  marquee1.value= marquee1.value + showString.charAt(index);
  index++;
  }
var timeID= setTimeout("marquee(suchbegriff)",100);
if (index >= stringLength)
  {
  clearTimeout(timeID);
  index=-1;
  }
}
</script>

PHP-Code
<?php
$pfad = $_SERVER['DOCUMENT_ROOT'];
$pfad = $pfad . "/path/file.php";
include ($pfad);
$datenbanktabelle = 'sprueche';
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
$datenzugriff =mysqli_connect($server, $user, $pass, $datenbank, 3306);
$suchergebnis = array();

$alles = mysqli_query($datenzugriff, "SELECT zaehler FROM $datenbanktabelle");
$eintragsanzahl = mysqli_num_rows($alles); 
$randvar = rand(0, $eintragsanzahl-1);
$suchergebnis = mysqli_query($datenzugriff, "SELECT * FROM $datenbanktabelle WHERE zaehler like '$randvar'");
$suchbegriff = mysqli_fetch_array($suchergebnis);
mysqli_close($datenzugriff);
$suchbegriff[1] = utf8_encode($suchbegriff[1]);
print ("<script language='JavaScript' type='text/JavaScript'> var suchbegriff = '" . $suchbegriff[1] . "'; marqueeA(suchbegriff); </script>");
?>

Output


Reiner Beckmann's Avatar Reiner Beckmann
Hhhhmmm, may be the problem is different. I kick off jce-Editor, and make a new Installation to get the Defaults. Then I testet to include the PHP-File, that works fine out of Joomla. The same Problem. But if a put the same code to include the file directly in the module, and not in a article, whitch is included in the module, it works fine. ?? 🙂

To include the article, I use your Extension "Articles Anywhere"
Peter van Westen's Avatar Peter van Westen ADMIN
Going by your screenshots you are not using Sourcerer.
Where are the {source} tags?
Please post a rating at the Joomla! Extensions Directory
Reiner Beckmann's Avatar Reiner Beckmann
First of all, I delete everything in the article. After that, I wrote the following code in the article
{source}<?php
include JPATH_SITE.'/path/file.php';
?>{/source}

The Script works in the "normal" article fine. But when I use the combination with "Article Anywhere" and "Sourcer", to put the Output of the Script in den frontend on a module-place, it dont work anymore. After that, I open my eyes, and saw, that it should be able, to write the same code direct in the Module, it works fine also in a module-place.
Peter van Westen's Avatar Peter van Westen ADMIN
It is probably due to the system plugin ordering. Try changing the ordering of the plugins in question.
See: regularlabs.com/blog/242-plugin-order-is-important
Please post a rating at the Joomla! Extensions Directory
You can only post on this forum if you log in