Results 1 to 5 of 5

Thread: PHP output effects JAVASCRIPT code... HELP

  1. #1
    Join Date
    Jul 2008
    Posts
    65
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default PHP output effects JAVASCRIPT code... HELP

    Hey there,
    I am developing a website in PHP. I am not great at javascript, and have been playing around with javascript/AJAX.

    I have a news page, and I am using a JS/Ajax pagination script off dynamic drive. It has an external .js file, and in that file the code that controls what is on each page is something like

    "page1.php","page2.php","page3.php" etc...

    Now that is all fine and dandy BUT I want the amount of pages to depend on the amount of news from a mysql database....

    I can use php, mysql, and a while loop to get a variable as follows:
    $links="\"page1.php","page2.php",....."pagex.php\""

    How can I then use this in the .js file to create 'x' pages..
    When I simply put the php code in the js file nothing happens.

    Hope that makes sense. Help greatly appreciated..

  2. #2
    Join Date
    Sep 2008
    Posts
    119
    Thanks
    13
    Thanked 0 Times in 0 Posts

    Default

    are you talking about creating an array?

    http://www.hunlock.com/blogs/Masteri...ascript_Arrays

  3. #3
    Join Date
    Jul 2008
    Posts
    65
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default

    Yes, I want to make an array.
    Basically the links for each page in this pagination script are stored in an array in the .js file.

    What I want to do is make it so depending on the number of rows in a mysql db table, the array changes. So If there are 50 rows, 5 pages. 40 rows, 4 pages..

    I can do that in PHP using while loops BUT how do I put PHP code into a .js file...

  4. #4
    Join Date
    Sep 2008
    Posts
    119
    Thanks
    13
    Thanked 0 Times in 0 Posts

    Default

    One trick is to use php to echo the javascript

    Code:
    <?
    echo "<script type=\"text/javascript\">";
    
    yourfunctionhere();
    
    echo "</script>"';
    
    ?>
    alternatively, you could use php to create a js file. I tried the "src=whatever.php" in a javascript tag, and it worked fine.

    Hope this helps. Displaying some of the code would help me more.

  5. #5
    Join Date
    Sep 2008
    Posts
    119
    Thanks
    13
    Thanked 0 Times in 0 Posts

    Default

    and if you are simply talking about echoing php in javascript it's simple.

    Code:
    <script type="text/javascript">
    alert('<? echo "this works"; ?>');
    </script>
    document.write is document.wrong

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •