Mate, it worked! Everything is easy once you know the answer... Thanks a million for a quick and valuable reply! 🆒
I had to do some fiddling to get the output right - specific nesting of variables seems to be very important; I also had to include " " in one array - otherwise it didn't work. Here is the complete version of this part of the scriptfor the benefit of others struggling with a similar problem:
for ($i = 0; ($i < count($pID)); $i++) {
$result=mysql_query("select * from $table where ClientID= '$pID[$i]' ;")
or die ("Unable to connect to database ");
while ($row = mysql_fetch_array($result)) {
$arrno1[] = $row['NUMBER1'];
$arrno2[] = $row['NUMBER2'];
$arrtx[] = $row['NAME'];
}
$arr1 = implode( ',' , $arrno1 );
$arr2 = implode( ',' , $arrno2 );
$arr3 = implode( '\',\'' , $arrtx );
}
echo "var a = [ $arr1 ];";
echo "var b = [ $arr2 ];";
echo "var c = ['$arr3'];";
The above script generates the following output in html:
var a = [ 100,158];var b = [ 20.50,40.88];var c = ["string 1","string2"];
If I could follow with a related question/ challenge...
Is there a better way to add " " to individual values in the array ? (I need to have them as strings otherwise the rest of my script doesn't work...)
How to combine values from $row and some html BEFORE making them into an array? For example:
From my first post, if this is what I want to output to an array variable (ie the lot as one value):
echo "<font face=\"Arial, Helvetica, sans-serif\" size=\"-1\"><a href=\"javascript:getit('".$row[Name] ."')\">".$row[Description]."</a></font><br>";
and then to have it printed in html as:
var c = [ '<font face="Arial, Helvetica, sans-serif" size="-1"><a href="javascript:getit('Name1')">"Description 1"</a></font><br>', '<font face="Arial, Helvetica, sans-serif" size="-1"><a href="javascript:getit('Name2')">"Description 2"</a></font><br>']
(not the most efficient and "recommended" way of formatting html and using javascript, I know, but just for the sake of working out this example let's assume it's ok).
Thanks