orbitter Posted March 4, 2008 Share Posted March 4, 2008 :'(hi there, i was wondering how to make the following javascript file work within the same webpage as this php file. can anyone help me please? this is the php: <?php // Make a MySQL Connection mysql_connect("localhost", "rooooo", "somethng") or die(mysql_error()); mysql_select_db("experiment") or die(mysql_error()); $noobs= mysql_query("SELECT * FROM names ORDER BY RAND()"); $no_of_noobs= mysql_num_rows($noobs); if ($no_of_noobs == "0"){ echo "No noobs could be selected from the db"; }else{ $the= mysql_fetch_object($noobs); echo $the->username; } ?> this is the javascript: <html> <head> <body> <script> <!-- //enter refresh time in "minutes:seconds" Minutes should range from 0 to inifinity. Seconds should range from 0 to 59 var limit="0:30" if (document.images){ var parselimit=limit.split(":") parselimit=parselimit[0]*60+parselimit[1]*1 } function beginrefresh(){ if (!document.images) return if (parselimit==1) window.location.reload() else{ parselimit-=1 curmin=Math.floor(parselimit/60) cursec=parselimit%60 if (curmin!=0) curtime=curmin+" minutes and "+cursec+" seconds left until page refresh!" else curtime=cursec+" seconds left until page refresh!" window.status=curtime setTimeout("beginrefresh()",1000) } } window.onload=beginrefresh //--> </script> </body> </html> Quote Link to comment Share on other sites More sharing options...
CrazeD Posted March 4, 2008 Share Posted March 4, 2008 <?php // Make a MySQL Connection mysql_connect("localhost", "root", "fadiyounes746") or die(mysql_error()); mysql_select_db("experiment") or die(mysql_error()); $noobs= mysql_query("SELECT * FROM names ORDER BY RAND()"); $no_of_noobs= mysql_num_rows($noobs); if ($no_of_noobs == "0"){ echo "No noobs could be selected from the db"; }else{ $the= mysql_fetch_object($noobs); echo $the->username; } ?> <html> <head> <body> <script> <!-- //enter refresh time in "minutes:seconds" Minutes should range from 0 to inifinity. Seconds should range from 0 to 59 var limit="0:30" if (document.images){ var parselimit=limit.split(":") parselimit=parselimit[0]*60+parselimit[1]*1 } function beginrefresh(){ if (!document.images) return if (parselimit==1) window.location.reload() else{ parselimit-=1 curmin=Math.floor(parselimit/60) cursec=parselimit%60 if (curmin!=0) curtime=curmin+" minutes and "+cursec+" seconds left until page refresh!" else curtime=cursec+" seconds left until page refresh!" window.status=curtime setTimeout("beginrefresh()",1000) } } window.onload=beginrefresh //--> </script> </body> </html> Like that? ... ??? Quote Link to comment Share on other sites More sharing options...
orbitter Posted March 4, 2008 Author Share Posted March 4, 2008 i have tried that but it doesnt seem to be working. when i save the javascript as a .html file by itself it works fine. but when i do that and save it as a .php file it doesnt seem to work. any ideas? thanks for the help. Quote Link to comment Share on other sites More sharing options...
phpSensei Posted March 4, 2008 Share Posted March 4, 2008 You save the file as .php, and do what CrazeD did. It should work, if not, its your javascript. Check your browser if it found any errors Quote Link to comment Share on other sites More sharing options...
orbitter Posted March 4, 2008 Author Share Posted March 4, 2008 i have tried the javascript by itself with a .html extension and it works pefectly. but when i did what crazeD did, then the browser only ouputs the php content and does not execute the content of the javascript. do you know why this happens? Quote Link to comment Share on other sites More sharing options...
phpSensei Posted March 4, 2008 Share Posted March 4, 2008 i have tried the javascript by itself with a .html extension and it works pefectly. but when i did what crazeD did, then the browser only ouputs the php content and does not execute the content of the javascript. do you know why this happens? Did you put the javascript in the head content? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.