Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Writing javascript function with php
Old 05-31-2009, 12:13 AM Writing javascript function with php
Sleeping Troll's Avatar
Ultra Talker

Posts: 351
Name: Butch Begy
Trades: 0
I am "writing" a javascript function to my page with php:
Code:
 
<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:
Code:
 
<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:
Code:
 
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?
__________________
Sleeping Troll, EMUSE, Mind Expansion...Truly serendipity!
Sleeping Troll is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-31-2009, 12:57 AM Re: Writing javascript function with php
Super Talker

Posts: 134
Name: Larry
Trades: 0
You call this function InitialOrbData() before you define it.

Move this line: "<script type="text/javascript" src="Scripts/orbs.js"></script>" after the php codes. I think it will work.

__________________

Please login or register to view this content. Registration is FREE
| Play
Please login or register to view this content. Registration is FREE
to kill time
larryatwt is offline
Reply With Quote
View Public Profile Visit larryatwt's homepage!
 
Reply     « Reply to Writing javascript function with php
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.24666 seconds with 12 queries