Sponsored by NuSphere - PHP Software for PHP Application Developers - On Sale This Week for $100



Go Back   PHP-Editors > Programming Help > PHP Programming Help

PHP Programming Help Post any question relating to PHP Programming here and hopefully someone can help.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 2005-12-20, 02:03 PM
Junior Member
 
Join Date: Dec 2005
Posts: 1
manamino
Default

please help me
I want inside a javascript function to bring data from database using php and put them in javascript array so that I can use them later, example after that alert the array like that:
function lolo()
{
var p=0;
var id=new array();

<?
$sql1=mysql_query("select * from sanction s, student st, officer o where s.Id=st.Id and s.Oid=o.Oid",$db);
while($row = mysql_fetch_array($sql1, MYSQL_NUM))
{?>
id[p]=<?=$row["Id"]?>;
p=p+1;
<?
}?>
var x=0;
for(x=0; x<=p; x++)
{
alert(id[x]);
}
}

this is the function but unfortunately not working any help!!!!!!!!
Reply With Quote
  #2 (permalink)  
Old 2005-12-20, 02:34 PM
Member
 
Join Date: Aug 2005
Location: Petoskey, MI
Posts: 83
n8dnx
Default

manamino:

The problem is that you're code assumes that the Javascript and the PHP code are executed concurrently. In actuality, the PHP code is executed to produce the output for the browser. That output contains the Javascript and no PHP code. Once the entire script is sent to the browser, the Javascript code is executed.

Perhaps what you want to do is to use PHP to echo out the necessary Javascript code to initialize the entire id array with all of the data in it.

Having said that, there are means to interactively work between PHP and Javascript, but frankly that's an entirely different animal. Get this working first.

Chuck
Reply With Quote
Must read Review for Serious PHP Developers


NuSphere PhpED 5.5 : The Staff of php-editors.com recently spent a few days working with NuSphere PhpED 5.5 (a popular PHP IDE) and NuCoder 2.0 (a PHP Encoding Utility), read up on all the details.

Sponsored Links
Reply

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 12:08 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.