Re: [PHP] Creating a javascript array from database data (Off-List)

2001-08-16 Thread Neil Freeman

Thanks for the clarification Sheridan - I think it must have been end of day
madness on my part :) I see what's going on now with the 'print' line.

Cheers,

Neil

Sheridan Saint-Michel wrote:

 ***
  This message was virus checked with: SAVI 3.48
  last updated 14th August 2001
 ***

 Think in terms of output...  The JavaScript is literally going to
 try and run the output of the PHP (It doesn't even know PHP
 exists).  PHP is outputting the source code for the HTML and
 JavaScript.  So what you are trying to do is get PHP to take
 dog,cat,cow from MySQL and output:

 Script Language=JavaScript
 text = new Array(dog,cat,cow)
 /Script

 This block of code does exactly that, with the print\$text\;
 filling in dog cat and cow.  I've added comments so you can
 see how each line produces the above (I am using C-Style
 comments as the // gets mucked up in e-mail)

 The parts in [] are comments within comments to show flow
 control and are not output.

 else
 {
 /* Script Language=JavaScript */
   echo Script Language=\JavaScript\\n;
 /* text=new Array( */
   echo text = new Array(;
   while ($i  $number)

 $text = mysql_result($result, $i, name);
 /* dog [first time] */
 /* cat [second time] */
 /* cow [third time] */
 print \$text\;
 $i++;
 if ($i  $number)
 /* , [first time] */
 /* , [second time] */
print ,;
 else
 /* ) [third time] */
   print )\n;
 }
 /* /Script */
   echo /Script\n;
 }

 So if you can follow that (just walk all the way through
 the loop for each of the three passes) you can see that
 no part of the code (including the print \$text\;) is
 unnecessary

 Hope this helps

 Sheridan Saint-Michel
 Website Administrator
 FoxJet, an ITW Company
 www.foxjet.com

 - Original Message -
 From: Neil Freeman [EMAIL PROTECTED]
 To: Sheridan Saint-Michel [EMAIL PROTECTED]
 Cc: php-general [EMAIL PROTECTED]
 Sent: Wednesday, August 15, 2001 12:09 PM
 Subject: Re: [PHP] Creating a javascript array from database data

  Thanks a lot for your help Sheridan,
 
  This now appears to work ok :) but if I remove the:
 
  print \$text\;
 
  line (as it is not required), I receive errors complaining about a syntax
  error (related to what?) and that 'text' is undefined. As this line simply
  outputs the value to screen why should this cause a problem if it is
 removed?
  Or could it be some other problem?
 
  Neil
 
  PS: Here is my updated code:
 Snip

--

 Email:  [EMAIL PROTECTED]
 [EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Creating a javascript array from database data (Off-List)

2001-08-15 Thread Sheridan Saint-Michel

Think in terms of output...  The JavaScript is literally going to
try and run the output of the PHP (It doesn't even know PHP
exists).  PHP is outputting the source code for the HTML and
JavaScript.  So what you are trying to do is get PHP to take
dog,cat,cow from MySQL and output:

Script Language=JavaScript
text = new Array(dog,cat,cow)
/Script

This block of code does exactly that, with the print\$text\;
filling in dog cat and cow.  I've added comments so you can
see how each line produces the above (I am using C-Style
comments as the // gets mucked up in e-mail)

The parts in [] are comments within comments to show flow
control and are not output.

else
{
/* Script Language=JavaScript */
  echo Script Language=\JavaScript\\n;
/* text=new Array( */
  echo text = new Array(;
  while ($i  $number)


$text = mysql_result($result, $i, name);
/* dog [first time] */
/* cat [second time] */
/* cow [third time] */
print \$text\;
$i++;
if ($i  $number)
/* , [first time] */
/* , [second time] */
   print ,;
else
/* ) [third time] */
  print )\n;
}
/* /Script */
  echo /Script\n;
}

So if you can follow that (just walk all the way through
the loop for each of the three passes) you can see that
no part of the code (including the print \$text\;) is
unnecessary

Hope this helps

Sheridan Saint-Michel
Website Administrator
FoxJet, an ITW Company
www.foxjet.com


- Original Message -
From: Neil Freeman [EMAIL PROTECTED]
To: Sheridan Saint-Michel [EMAIL PROTECTED]
Cc: php-general [EMAIL PROTECTED]
Sent: Wednesday, August 15, 2001 12:09 PM
Subject: Re: [PHP] Creating a javascript array from database data


 Thanks a lot for your help Sheridan,

 This now appears to work ok :) but if I remove the:

 print \$text\;

 line (as it is not required), I receive errors complaining about a syntax
 error (related to what?) and that 'text' is undefined. As this line simply
 outputs the value to screen why should this cause a problem if it is
removed?
 Or could it be some other problem?

 Neil

 PS: Here is my updated code:
Snip


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]