|
|||||||
| PHP Discussion and technical support for using and deploying PHP based websites. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
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:
Greetz tAK |
|
#2
|
||||
|
||||
|
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 |
|
#3
|
||||
|
||||
|
Quote:
|
|
#4
|
||||
|
||||
|
Quote:
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.
__________________
Stephen Free Computer Help, blog, forum Web design ebooks and software JavaScript scripts and tutorials |
|
#5
|
||||
|
||||
|
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 |
|
#6
|
||||
|
||||
|
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> 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 |
|
#7
|
||||
|
||||
|
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:
__________________
Email me | CAPTCHA verification script | DNS speed test | Email address tester | Regex checker | PHP scripts | Do it yourself avatars Cruft free domain names | English Spanish Translation | Watermarking images | Freelance | Texas Holdem Poker Probability Calculator Last edited by bokeh; 05-22-2005 at 05:12 PM. |
|
#8
|
||||
|
||||
|
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 |
|
#9
|
||||
|
||||
|
That's like saying a client cannot communicate directly with a server because the internet is a middleman between the two.
|
|
#10
|
||||
|
||||
|
Okey, I'm not using XML, I'm not gonna learn ANOTHER language... got twenty of 'm already... anyway is this possible:
Quote:
|
|
#11
|
||||
|
||||
|
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 |
|
#12
|
|||
|
|||
|
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." |
|
#13
|
||||
|
||||
|
Please don't reply to threads that are 2 1/2 years old already.
|
|
#14
|
|||
|
|||
|
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. |
|
#15
|
||||
|
||||
|
Because it's not helpful to the OP.
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|