SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    HI silver trophy Silverado4x4's Avatar
    Join Date
    Jan 2001
    Location
    USA
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Creating a dynamic javascript include

    Here's the dilemma:

    I am creating a link exchange program for a client. Everything is basically finished except the javascript include.

    We would like members to put a javascript code onto their website, which will pull results from our database, and will display them on the page.

    I have no knowledge of javascript, so I am stuck at this point. I need to know how to integrate PHP into JavaScript if it is possible, and if not, what other workarounds there are with javascript.

    Thank you for your time.

    edit: Please move this to the JavaScript forum. I accidently hit submit before I realized I was in the PHP forum.

  2. #2
    SitePoint Guru
    Join Date
    Aug 2001
    Location
    Amsterdam
    Posts
    788
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmmm what has the script got to do prezisely could you give an example ???
    the neigbours (free) WIFI makes it just a little more fun

  3. #3
    HI silver trophy Silverado4x4's Avatar
    Join Date
    Jan 2001
    Location
    USA
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The javascript needs to pull some entries out of the MySQL database. It should then write a table (using document.write() ?) so it would be viewable on the members' website if they do a javascript include.

    I have the PHP written, but I'm not sure how to integrate this with javascript.

    I am clueless when it comes to javascript.

  4. #4
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yip, done this a while back

    Here is some script that you would need - you will need to modify the query which pulls the data out of the database and format the TABLE as you need, though the script works.

    You put the file in your server, give your client a link which they put in their web page and bingo - they have the data displayed in their site

    PHP Code:
    # template file
    #
    /* database driven content feed using PHP and Javascript */
     /*
     step 1: include following in seperate PHP file.
     step 2: place following Javascript tag below in BODY of document as required.
     
      <script language="javascript1.2" type="text/javascript" src="*.php"></script>
     
     step 3: file required to grab content from database and display to basic HTML page.
     */
     
     <?
    # INCLUDE db class
     
    include_once("../classes.php");
     
     
    $db = new db_connect;
     
    $db -> select_user_db();
     
     if(!
    $db) { ?> document.write("Cound not load content feed."); <? }
     
     
    $sql $db -> query_user_db("SELECT ** FIELDS TO USE ** FROM ** TABLE TO USE ** ORDER BY ** PRIMARY KEY **");
     
    ?>
     document.write("<table border='0' width='512' align='center' valign='top' cellspacing='2' cellpadding='0'><tbody>");
     <?
     
    while($row mysql_fetch_array($sql))
     {
      
    $ID $row["** ID **"];
      
    $TITLE $row["** TITLE **"];
      
    ?>
      document.write("<tr><td align='left' width='100%' height='24' valign='center'>&nbsp;");
      document.write("<a href="*.php?id=<? echo($ID); ?>" target='_blank'>");
      document.write("<font size='2' face='verdana' color='black'><? echo($TITLE); ?></font>");
      document.write("</a></td></tr>");
      <?
     
    }
     
    ?>
     document.write("</tbody></table>");
    Remember to give the file a PHP extension - it'll still work from the point of view of Javascript.

    As an alternative if Javascript could be disabled, think about webservices - maybe something to think about at a later date.

  5. #5
    HI silver trophy Silverado4x4's Avatar
    Join Date
    Jan 2001
    Location
    USA
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's crazy...I didn't think it would work if it didn't have the .js extension.

    Thanks a ton for clearing this up for me.

  6. #6
    HI silver trophy Silverado4x4's Avatar
    Join Date
    Jan 2001
    Location
    USA
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Works perfectly, thanks!


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
  •