Wednesday 15 September 2010

PHP mysql inside Javascript -


I've searched a lot and can not find what I'm looking for.

I have a .js field, and I really need help with some php code I do not know how to get them together And really will appreciate some help.

Javascript code (this code is inside the JS file):

  & lt; Span class = "Gravatar" & gt; & Lt; Img src = "'params.gravatar," "width =" 23 "height =" 23 "onload =" this.style.visibility = \' visible \ "/>   < P> Where  & lt; img src = "', params.gravatar," "& gt;   

I want to add:

  & lt ;? Php $ con = mysqli_connect ("localhost", "root", "", "facebook"); If (mysqli_connect_errno ()) {echo "failed to connect to MySQL:". Mysqli_connect_error (); } $ Result = mysqli_query ($ con, "SELECT * FROM login WHERE username = '$ username'"); $ Username = $ _SESSION ['Username']; While ($ row = mysqli_fetch_array ($ result)) {echo $ line ['profiles']; Echo "& lt; br & gt;"; Mysqli_close ($ thief); }? & Gt;   

setting, params.gravatar,

I accept you Which means that the HTML snippet you are posting is inside a separate JS file. If this is the case, then you can assign a profile picture url to your PHP code in the global JS variable:

Your PHP file:

  & lt ;? Php // your DB call code goes here ...? & Gt; & Lt; Script & gt; Var ProfilePic = '& lt ;? = $ Row ['Profile']? & Gt; '; & Lt; / Script & gt; & Lt; Script src = "/ your / jsfile.js" & gt; & Lt; / Script & gt;   

and your jsFile.js :

  var img = '& lt; Span class = "gravatar" & gt; & Lt; IMG src = "'+ + ProfilePic +" "width =" 23 "height =" 23 "/>';    

No comments:

Post a Comment