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> Link to comment https://forums.phpfreaks.com/topic/94381-php-with-javascript/ 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? ... ??? Link to comment https://forums.phpfreaks.com/topic/94381-php-with-javascript/#findComment-483344 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. Link to comment https://forums.phpfreaks.com/topic/94381-php-with-javascript/#findComment-483348 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 Link to comment https://forums.phpfreaks.com/topic/94381-php-with-javascript/#findComment-483354 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? Link to comment https://forums.phpfreaks.com/topic/94381-php-with-javascript/#findComment-483360 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? Link to comment https://forums.phpfreaks.com/topic/94381-php-with-javascript/#findComment-483370 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.