Jump to content

php with javascript


orbitter

Recommended Posts

:'(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
Share on other sites

<?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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.