hi, I wanted to display news using javascript from a different hml file.

Here is the code i have used

inews.php file

<?php

require_once("C:\www\Apache\htdocs\mainfile.php");

global $dbi;
$perpage=10;

$result=mysql_query("Select newsid,headline from inews  ORDER BY newsid DESC limit $perpage",$dbi);
while(list($newsid,$headline)=mysql_fetch_row($result)) {

$news="<strong><big>.</big></strong>&nbsp;<a href=\"http://localhost/inews.php?name=inews&file=index&action=click&amp;newsid=$newsid\">$headline</a>&nbsp<br>";

echo "<script language=\"JavaScript\">\n";
echo "document.write('$news')";
echo "</script>";


}

?>

And code to display news in any html file are

<script src="http://localhost/inews.php"></script>

It's not working .. What did i missed ?

😕

    the problem is here

    require_once("C:\www\Apache\htdocs\mainfile.php");

    when u call the file as

    http://localhost/inews.php

    it wont understand the path to the mainfile.php script and hence will give u an error

    Try writing as

    require_once("mainfile.php");

    where mainfile.php is in the same directory where the script is in which u are writing this line
    🆒

      Any help... could not solve the problem ?

        Oh yeah, and you dont need javascript to print out the news. Just use:
        echo $news;

        instead of:
        echo "<script language=\"JavaScript\">\n";
        echo "document.write('$news')";
        echo "</script>";

          I solved the the problem ..the the pronlem was in the php code

          instead of

          echo "<script language=\"JavaScript\">\n"; 
          echo "document.write('$news')"; 
          echo "</script>";
          

          it should be

          echo "document.write('$news');";

          It's work perfact when i call the php file by javascript.

            Write a Reply...