SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jan 2004
    Location
    UK
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Output data from mysql database in javascript?

    Not sure if this is the correct forum as it covers data retrieved from mysql in a .js file...

    I need to grab the last 5 rows from my database (2 fields per row) and list all 5 in a table but from within a .js file that I can externally link to.

    I can manage the php / mysql and the output to a .php page but how can this be contained within a .js file?

    I believe it is possible but after 2 days of searching on google I'm appealing for assistance.

    I realise this could be done with a php include or iframe but that isn't an option and the only way available to import this data is via an external javascript script.

    Appreciate any help that anyone can offer.

    Regards

    Vanlaywan

  2. #2
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,424
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Have the PHP echo/print javascript. The javascript then prints the html you need to display your table. I use this to allow other sites to add a joke of the day that I produce and put it on their site. Is this similar to what you're trying to do?

  3. #3
    SitePoint Member
    Join Date
    Jan 2004
    Location
    UK
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Stymiee,

    Yes, I want to get the data loaded from the database and into a javascript file as I can use
    Code:
    <script type="text/javascript" src="location_of_file.js"></script>
    on the site. However my javascript coding knowledge is, well to be frank, miniscule

    I need the file to be .js but have no idea how to achieve this so the mysql data is in the file.

    Any coding examples you could offer would assist me regardng coding php into javascript.

    Regards

    Van

  4. #4
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,424
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Here's an example of what I did. It should give you the right idea (This is the output of the php):

    Code:
    document.write("<STYLE>")
    document.write("A.johnny:link 		{color: white;}")
    document.write("A.johnny:active 	{color: white;}")
    document.write("A.johnny:visited 	{color: white;}")
    document.write("A.johnny:hover 		{text-decoration: underline;}")
    document.write("</STYLE>")
    document.write("<CENTER>")
    document.write("<TABLE CELLPADDING=5 CELLSPACING=0 style='border-style: solid; border-color: #808080; border-width: 5px;' WIDTH=80%>")
    document.write("<TR><TD BGCOLOR='#111B7F' ALIGN=CENTER><B><FONT FACE='verdana, arial, helvetica' color=white>Football Lingo</FONT></B></TD></TR>")
    document.write("<TR><TD BGCOLOR='#111B7F'> &nbsp; </TD></TR>")
    document.write("<TR><TD BGCOLOR='#111B7F'><FONT FACE='verdana, arial, helvetica' color=white size=2>A guy comes home from the bar drunk one night around 3 in the morning. His wife is sleeping and he is trying to sneak into bed. He\'s laying in bed for a few minutes and cuts a fart. His wife wakes up and asks, \"What in the world was that?\"<BR><BR>He replies, \"Touchdown, I am winning 7 nothing.\"<BR><BR>She thinks to herself, \"I\'m gonna fix him.\" Then she lets one loose.<BR><BR>He yells at her, \"What was that?\"<BR><BR>She replies \"Touchdown, tie score.\"<BR><BR>Now he thinks, \"I\'m gonna fix her.\" He\'s laying there for about 10 minutes trying to work one up. He tries so hard he ****s in bed.<BR><BR>The wife asks, \"Now what in the world was that?\"<BR><BR>He replied, \"Half time, switch sides.\" </FONT></TD></TR>")
    document.write("<TR><TD BGCOLOR='#111B7F'> &nbsp; </TD></TR>")
    document.write("<TR><TD BGCOLOR='#111B7F'><FONT FACE='verdana, arial, helvetica' color=white size=2>This joke was brought to you by <A HREF='http://www.johnnysjokes.com' class=johnny>Johnny's Jokes</A></FONT></TD></TR>")
    document.write("</TABLE>")
    document.write("</CENTER>")
    Someone would add this to their page this way:

    Code:
    <script type="text/javascript" src="http://www.johnnysjokes.com/web/webmasters/addjotd/addjokes.php"> </script>


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
  •