Sleeping_Troll
05-31-2009, 03:53 AM
I am "writing" a javascript function to my page with php:
<html>
<head>
<title>Just about everything</title>
<script type="text/javascript" src="Resources/prototype.js"></script>
<script type="text/javascript" src="Scripts/orbs.js"></script>
<script type='text/javascript'>
function InitialOrbData(){
<?php
for ($i=0;$i<50;$i++){
$offset_result = mysql_query( " Select Floor(Rand() * Count(*)) As `offset` From `Sites` ");
$offset_row = mysql_fetch_object( $offset_result );
$offset = $offset_row->offset;
$SQL="SELECT * FROM Sites LIMIT $offset, 1";
$OrbData = mysql_query($SQL);
$OrbRow = mysql_fetch_array($OrbData);
$Orb[i]= array(ID=>$OrbRow[0],TYPE=>$OrbRow[1],URL=>$OrbRow[2],KEYWORDS=>$OrbRow[3],BID=>$OrbRow[4]);
echo ("
Orb[".$i."].ID='".$Orb[i]['ID']."';
Orb[".$i."].TYPE='".$Orb[i]['TYPE']."';
Orb[".$i."].URL='".$Orb[i]['URL']."';
Orb[".$i."].KEYWORD='".$Orb[i]['KEYWORD']."';
Orb[".$i."].BID='".$Orb[i]['BID']."';
");
}
?>
}
</script>
The function appears quite normal on the page:
<html>
<head>
<title>Just about everything</title>
<script type="text/javascript" src="Resources/prototype.js"></script>
<script type="text/javascript" src="Scripts/orbs.js"></script>
<script type='text/javascript'>
function InitialOrbData(){
Orb[0].ID='9263517364090098';
Orb[0].TYPE='normal';
Orb[0].URL='http:// www.ringernation.com';
Orb[0].KEYWORD='';
Orb[0].BID='0.00';
Orb[1].ID='2147483647476592';
Orb[1].TYPE='sponsored';
Orb[1].URL='http:// www.ringernation.com';
Orb[1].KEYWORD='';
Orb[1].BID='0.00';
Orb[2].ID='9364555231142958';
Orb[2].TYPE='normal';
Orb[2].URL='http://www.ringernation.com';
Orb[2].KEYWORD='';
Orb[2].BID='0.00';
...
Orb[48].ID='2147483647476592';
Orb[48].TYPE='sponsored';
Orb[48].URL='http:// www.ringernation.com';
Orb[48].KEYWORD='';
Orb[48].BID='0.00';
Orb[49].ID='9263517364090098';
Orb[49].TYPE='normal';
Orb[49].URL='http:// www.ringernation.com';
Orb[49].KEYWORD='';
Orb[49].BID='0.00';
}
</script>
notice the script include in red in the first code section, it references the php written script as shown below:
var numOrbs=36; //number of Orbs
var InitialVelocity;
var Zeye; //perspective:distance of eye from box centre
var Zscreen; //perspective:distance of screen from box centre
var OrbBaseRadius
var OrbProximityFactor;
var Xmin,Ymin,Xmax,Ymax,Zmin,Zmax;
var Perspective;
var Dimensions=[];
var Orb=[];
InitialOrbData();
alas I get the error InitialOrbData is not defined, can anybody tell me why?
<html>
<head>
<title>Just about everything</title>
<script type="text/javascript" src="Resources/prototype.js"></script>
<script type="text/javascript" src="Scripts/orbs.js"></script>
<script type='text/javascript'>
function InitialOrbData(){
<?php
for ($i=0;$i<50;$i++){
$offset_result = mysql_query( " Select Floor(Rand() * Count(*)) As `offset` From `Sites` ");
$offset_row = mysql_fetch_object( $offset_result );
$offset = $offset_row->offset;
$SQL="SELECT * FROM Sites LIMIT $offset, 1";
$OrbData = mysql_query($SQL);
$OrbRow = mysql_fetch_array($OrbData);
$Orb[i]= array(ID=>$OrbRow[0],TYPE=>$OrbRow[1],URL=>$OrbRow[2],KEYWORDS=>$OrbRow[3],BID=>$OrbRow[4]);
echo ("
Orb[".$i."].ID='".$Orb[i]['ID']."';
Orb[".$i."].TYPE='".$Orb[i]['TYPE']."';
Orb[".$i."].URL='".$Orb[i]['URL']."';
Orb[".$i."].KEYWORD='".$Orb[i]['KEYWORD']."';
Orb[".$i."].BID='".$Orb[i]['BID']."';
");
}
?>
}
</script>
The function appears quite normal on the page:
<html>
<head>
<title>Just about everything</title>
<script type="text/javascript" src="Resources/prototype.js"></script>
<script type="text/javascript" src="Scripts/orbs.js"></script>
<script type='text/javascript'>
function InitialOrbData(){
Orb[0].ID='9263517364090098';
Orb[0].TYPE='normal';
Orb[0].URL='http:// www.ringernation.com';
Orb[0].KEYWORD='';
Orb[0].BID='0.00';
Orb[1].ID='2147483647476592';
Orb[1].TYPE='sponsored';
Orb[1].URL='http:// www.ringernation.com';
Orb[1].KEYWORD='';
Orb[1].BID='0.00';
Orb[2].ID='9364555231142958';
Orb[2].TYPE='normal';
Orb[2].URL='http://www.ringernation.com';
Orb[2].KEYWORD='';
Orb[2].BID='0.00';
...
Orb[48].ID='2147483647476592';
Orb[48].TYPE='sponsored';
Orb[48].URL='http:// www.ringernation.com';
Orb[48].KEYWORD='';
Orb[48].BID='0.00';
Orb[49].ID='9263517364090098';
Orb[49].TYPE='normal';
Orb[49].URL='http:// www.ringernation.com';
Orb[49].KEYWORD='';
Orb[49].BID='0.00';
}
</script>
notice the script include in red in the first code section, it references the php written script as shown below:
var numOrbs=36; //number of Orbs
var InitialVelocity;
var Zeye; //perspective:distance of eye from box centre
var Zscreen; //perspective:distance of screen from box centre
var OrbBaseRadius
var OrbProximityFactor;
var Xmin,Ymin,Xmax,Ymax,Zmin,Zmax;
var Perspective;
var Dimensions=[];
var Orb=[];
InitialOrbData();
alas I get the error InitialOrbData is not defined, can anybody tell me why?