www.webdeveloper.com
Recent Articles
  • Finding Slow Running Queries in ASE 15
  • A More Advanced Pie Chart for Analysis Services Data
  • Adobe AIR Programming Unleashed: Working with Windows
  • Performance Testing SQL Server 2008's Change Data Capture Functionality
  • The ABC's of PHP: Introduction to PHP
  • How to Migrate from BasicFiles to SecureFiles Storage
  • Why the Twitter Haters Are Wrong
  • User Personalization with PHP: Beginning the Application
  • Whats in an Oracle Schema?
  • Lighting Enhancement in Photoshop
  •  

    Go Back   WebDeveloper.com > Server-Side Development > PHP

    PHP Discussion and technical support for using and deploying PHP based websites.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1  
    Old 05-22-2005, 01:15 PM
    The Anime King's Avatar
    The Anime King The Anime King is offline
    tAK --> flappy
     
    Join Date: Jan 2004
    Location: Holland
    Posts: 108
    Javascript & MySQL

    Every visitor on my site gets an automatic MySQL table with stats like screen size, ip, browser etc.

    Now everything is saved in the user table, but there's a little problem.
    How can I update a javascript code like screen.width?
    PHP Code:
    Update user SET screen=screen.width WHERE ip=$ip;
    That's not working... Is there a PHP code for it? Or how can I fix it?
    Greetz tAK
    __________________
    [ My Website: Eclypz Online ]

    Life sucks, enjoy it -The Anime King
    Reply With Quote
      #2  
    Old 05-22-2005, 04:06 PM
    grailquester5's Avatar
    grailquester5 grailquester5 is offline
    3rd Planet Native
     
    Join Date: Apr 2005
    Location: Portsmouth, UK
    Posts: 157
    JavaScript is a client-side language, PHP/MySQL are server-side, hence they don't speak directly to one another. The only way (I know of) to pass values from JavaScript to PHP is to create an invisible form and populate it with the information that you'd like to pass (or pass it in a URL as in a GET statement and then use PHP to interpret the GET).
    __________________
    I am the sum of the lack of all knowledge...
    Before You Ask Any Questions...
    aim54 Digital Solutions
    Reply With Quote
      #3  
    Old 05-22-2005, 04:21 PM
    bokeh's Avatar
    bokeh bokeh is offline
    Keep it simple, stupid!
     
    Join Date: Jan 2005
    Location: Alicante (Spain)
    Posts: 7,705
    Quote:
    Originally Posted by grailquester5
    JavaScript is a client-side language, PHP/MySQL are server-side, hence they don't speak directly to one another. The only way (I know of) to pass values from JavaScript to PHP is to create an invisible form and populate it with the information that you'd like to pass (or pass it in a URL as in a GET statement and then use PHP to interpret the GET).
    Actually javascript can send information to php behind the scenes without a new page load being necessary.
    Reply With Quote
      #4  
    Old 05-22-2005, 04:27 PM
    felgall's Avatar
    felgall felgall is offline
    Computer Consultant
     
    Join Date: Mar 2005
    Location: Sydney, Australia
    Posts: 7,979
    Quote:
    Originally Posted by bokeh
    Actually javascript can send information to php behind the scenes without a new page load being necessary.
    How can it do that when the PHP has finished running before the page reaches the browser and the Javascript doesn't start running until after that and so doesn't even know that there is PHP there to interact with?

    You can embed PHP into Javascript so that the PHP can generate the Javascript content but the other way around - I don't think so.
    Reply With Quote
      #5  
    Old 05-22-2005, 04:40 PM
    grailquester5's Avatar
    grailquester5 grailquester5 is offline
    3rd Planet Native
     
    Join Date: Apr 2005
    Location: Portsmouth, UK
    Posts: 157
    bokeh, I'm sorry, but no it can't. felgall is right - PHP runs first, on the server, and sends data to the browser. PHP can be used to create Javascript (just like HTML), but not vice-versa.

    PHP has 3 ways (one which I didn't mention previously) of getting data from javascript:

    1. Use Javascript to set a cookie and retrieve the cookie on another page using PHP.

    2. Append variables to a URL with Javascript, then use Javascript to redirect the browser to said URL (or have the user redirect it).

    3. Have Javascript set the value(s) of hidden input fields in a form and have the user submit the form.

    That's all there is to it.
    __________________
    I am the sum of the lack of all knowledge...
    Before You Ask Any Questions...
    aim54 Digital Solutions
    Reply With Quote
      #6  
    Old 05-22-2005, 04:43 PM
    The Anime King's Avatar
    The Anime King The Anime King is offline
    tAK --> flappy
     
    Join Date: Jan 2004
    Location: Holland
    Posts: 108
    I think I'm going to solve it with this line:
    HTML Code:
    <iframe src=stats.php?screen=<script>document.write(screen.width+"x"+screen.height);</script>&colors=<script>document.write(screen.colorDepth);</script>></iframe>
    But now I have another question. Is there a way to auto-refresh PHP code?
    Let's say Online() is a function that reads the SQL-database for online visitors, but after ten minutes of reading the info, maybe all visitors are gone and still it gives the same number... Is there a way to autorefresh only a little bit of PHP-code?

    Greetz tAK
    __________________
    [ My Website: Eclypz Online ]

    Life sucks, enjoy it -The Anime King
    Reply With Quote
      #7  
    Old 05-22-2005, 04:50 PM
    bokeh's Avatar
    bokeh bokeh is offline
    Keep it simple, stupid!
     
    Join Date: Jan 2005
    Location: Alicante (Spain)
    Posts: 7,705
    I'm sorry my friends but your technical knowledge is out of date. Full bi-directional communication is possible between javascript and the server (behind the scenes, ie no page loads being involved) with all modern browsers except Opera. If you dont believe me take a look at this and this and this.
    Quote:
    The XMLHttpRequest Object

    This object, first implemented by Microsoft as an ActiveX object but now also available as a native object within both Mozilla and Apple's Safari browser, enables JavaScript to make HTTP requests to a remote server without the need to reload the page. In essence, HTTP requests can be made and responses received, completely in the background and without the user experiencing any visual interruptions.

    Last edited by bokeh; 05-22-2005 at 05:12 PM.
    Reply With Quote
      #8  
    Old 05-22-2005, 05:11 PM
    grailquester5's Avatar
    grailquester5 grailquester5 is offline
    3rd Planet Native
     
    Join Date: Apr 2005
    Location: Portsmouth, UK
    Posts: 157
    bokeh, that's great - but that's XML - invoking an XML object (XMLHttpRequest). And although it can make use of Javascript and PHP, it is NEITHER Javascript NOR PHP. Hence - for those of us who don't know/use XML (yet), it is useless. The question was can Javascript send information to PHP? The answer is NO. XML, however, via their new object (XMLHttpRequest) can maintain an open connection and invoke Javascript on the client side and PHP on the server side (which IS great) - but again - it is neither PHP nor Javascript DOING this.
    __________________
    I am the sum of the lack of all knowledge...
    Before You Ask Any Questions...
    aim54 Digital Solutions
    Reply With Quote
      #9  
    Old 05-22-2005, 05:17 PM
    bokeh's Avatar
    bokeh bokeh is offline
    Keep it simple, stupid!
     
    Join Date: Jan 2005
    Location: Alicante (Spain)
    Posts: 7,705
    That's like saying a client cannot communicate directly with a server because the internet is a middleman between the two.
    Reply With Quote
      #10  
    Old 05-22-2005, 05:17 PM
    The Anime King's Avatar
    The Anime King The Anime King is offline
    tAK --> flappy
     
    Join Date: Jan 2004
    Location: Holland
    Posts: 108
    Okey, I'm not using XML, I'm not gonna learn ANOTHER language... got twenty of 'm already... anyway is this possible:
    Quote:
    But now I have another question. Is there a way to auto-refresh PHP code?
    Let's say Online() is a function that reads the SQL-database for online visitors, but after ten minutes of reading the info, maybe all visitors are gone and still it gives the same number... Is there a way to autorefresh only a little bit of PHP-code?
    __________________
    [ My Website: Eclypz Online ]

    Life sucks, enjoy it -The Anime King
    Reply With Quote
      #11  
    Old 05-22-2005, 08:09 PM
    grailquester5's Avatar
    grailquester5 grailquester5 is offline
    3rd Planet Native
     
    Join Date: Apr 2005
    Location: Portsmouth, UK
    Posts: 157
    King,

    If you're using an iframe, you could (I think - never having tried it) just reload that iframe (the frame's source). Javascript has a setTimeout() function which you could use in a loop to reload the content of said iframe, which would obviously be your "visitors.php" file or something...

    bokeh,

    Not even going to respond to that.
    __________________
    I am the sum of the lack of all knowledge...
    Before You Ask Any Questions...
    aim54 Digital Solutions
    Reply With Quote
      #12  
    Old 10-25-2007, 05:14 AM
    BurntHand BurntHand is offline
    Registered User
     
    Join Date: Oct 2007
    Posts: 1
    Wikipedia Quote:

    http://en.wikipedia.org/wiki/Ajax_(programming)

    "XML is sometimes used as the format for transferring data between the server and client, although any format will work, including preformatted HTML, plain text and JSON. These files may be created dynamically by some form of server-side scripting."
    Reply With Quote
      #13  
    Old 10-25-2007, 10:18 AM
    bokeh's Avatar
    bokeh bokeh is offline
    Keep it simple, stupid!
     
    Join Date: Jan 2005
    Location: Alicante (Spain)
    Posts: 7,705
    Please don't reply to threads that are 2 1/2 years old already.
    Reply With Quote
      #14  
    Old 05-12-2009, 05:53 PM
    meekythegeek meekythegeek is offline
    Registered User
     
    Join Date: May 2009
    Posts: 1
    Why not reply to old threads? It helped me when I reached this page through a search. If you don't want older posts being read and replied to then remove replying or remove the old posts. If there is new helpful information, then I think posting it for those who may stumble upon it later will only be a benefit.

    I mean I hope it doesn't hurt anyone's virtual pride because they made a comment in good faith based on older technology and now their advice is seen as obsolete.
    Reply With Quote
      #15  
    Old 05-13-2009, 03:23 AM
    bokeh's Avatar
    bokeh bokeh is offline
    Keep it simple, stupid!
     
    Join Date: Jan 2005
    Location: Alicante (Spain)
    Posts: 7,705
    Quote:
    Originally Posted by meekythegeek View Post
    Why not reply to old threads?
    Because it's not helpful to the OP.
    Reply With Quote
    Reply

    Bookmarks


    Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
     
    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is Off
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 04:26 AM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy

    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.