SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    using php in javascript

    Hey guys wasnt sure which forum to put this in (php or javascript), i have some code and i dynamically create an array using php, i then want to put this php variable in my javascript. Heres the code i have:

    PHP Code:
    <?php

    include "includes/db.php";

    $result mysql_query("SELECT * FROM tabQuote WHERE quoLive = 'y'") or die (mysql_error());

    $x 0;
    $box "";

    while (
    $row mysql_fetch_array($result)) {

        
    $x++;
        
    $box .= "'box-" $x "'";
        
        if (
    $x != mysql_num_rows($result)) {
            
            
    $box .= ", ";
            
        }
        
    }

    ?>

    <script src="../scriptaculous/lib/prototype.js" type="text/javascript"></script>
    <script src="../scriptaculous/src/scriptaculous.js" type="text/javascript"></script>
    <script language="javascript" type="text/javascript">
                
        // this array consists of the id attributes of the divs we wish to alternate between, edit for ammount of divs you need
        var divs_to_fade = new Array(<?php echo $box?>);
            
        // the starting index in the above array.  It should be set to the value of the div which doesn't have the CSS Display property set to "none"
        var i = 0;
                
        // the number of milliseconds between swaps.  Default is five seconds.
        var wait = 5000;

        // the function that performs the fade
        function swapFade() {
            Effect.Fade(divs_to_fade[i], { duration:2, from:2.0, to:0.0 });
            i++;
            if (i == <?php echo $x?>) i = 0;
            Effect.Appear(divs_to_fade[i], { duration:2, from:0.0, to:2.0 });
        }
                
        // the onload event handler that starts the fading.
        function startPage() {
            setInterval('swapFade()',wait);
        }

    </script>
    The only problem is the values arent displaying javascript

    Thanks in advance
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  2. #2
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    fixed, thanks
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"


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
  •