Web Analytics Made Easy -
StatCounter In need of JavaScript and interaction with a MySQL database... - CodingForum

Announcement

Collapse
No announcement yet.

In need of JavaScript and interaction with a MySQL database...

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • In need of JavaScript and interaction with a MySQL database...

    I've got a little script that takes a set of array values and displays these values in a box on a website. It's basically a news ticker with fade-in and fade-out capabilities. Well, my boss wants me to use this to pull some customer testimonials from a MySQL database and display them instead of news items.

    Currently the array and the corresponding news items are part of the script so it works flawlessly.

    Is there a way either using just JavaScript or both JavaScript and PHP that I can pull the customer testimonials from the MySQL database and populate the JavaScript array so that they display instead?

    Here's the website I'm working on http://www.oasisgamingusa.com/testlayout/index.php

    The JavaScript is part of the header section so you should be able to view the source to see what it looks like.

    Thanks

  • #2
    No, you can't access the database using JavaScript.

    You could use PHP to echo all of the values from your database into a series of <ul> elements on the page. Then hide these elements with JavaScript so that your users don't see them. From here, you could use JavaScript to read the contents of the <ul> element and assemble the values into an array that you format properly for your script to work with.

    Do you need more help with this?

    Comment


    • #3
      Why not just use php to build a javascript array. The same as you do currently. Just rather than hardcoding it, it pulls from the database.
      Helping to build a bigger box. - Adam Matthews

      Comment


      • #4
        How do you build a javascript array with PHP out of curiosity?

        Comment


        • #5
          Well, I don't code in php, but I would assume you could do something similar as to what I'd do in ASP:

          Code:
          <script type="text/javascript">
          var some_data=new Array();
          <%
             For i=0 To rs.RecordCount
          %>
                 some_data[<%=i%>]="<%=rs.Fields("somedata")%>";
          <%
             rs.MoveNext
             Next
          %>
          </script>
          Last edited by Basscyst; Oct 10, 2006, 07:51 PM.
          Helping to build a bigger box. - Adam Matthews

          Comment

          Working...
          X