Page 1 of 1
How I fill javascript array with php variables?
Posted: Wed Mar 31, 2004 12:38 am
by wiedzim
Hello,
I need fill javascript array with some php variables from
$vyber_osoba="SELECT ID,UZIVATEL,NAZEV FROM A_PRAVA WHERE UZIVATEL='".$_SESSION['uzivatel']."' ";
$vysledok_vyber_osoba = ODBC_Exec($pripojenie, $vyber_osoba );
while(ODBC_Fetch_Row($vysledok_vyber_osoba)):
$meno=ODBC_Result($vysledok_vyber_osoba, "ID").ODBC_Result($vysledok_vyber_osoba, "NAZEV").ODBC_Result($vysledok_vyber_osoba, "JMENO");
endwhile;
And I need put variables $meno into this array and variables must be saparate by comma
var selectbox = new Array('$meno0','$meno1' .... ); for example .....
It's possible, thank you very much
wiedzim
Posted: Wed Mar 31, 2004 1:18 am
by twigletmac
It is possible, just use PHP to echo out the Javascript.
Mac
var selectbox = new Array('$meno0','$meno1' .... ); for exam
Posted: Wed Mar 31, 2004 1:40 am
by wiedzim
hello twigletmac
you mean
var selectbox = new Array('<? echo $meno; ?>' );
thanks wiedzim
Posted: Wed Mar 31, 2004 1:48 am
by twigletmac
Exactly.
Mac
Posted: Wed Mar 31, 2004 2:04 am
by wiedzim
but its doesn't working the array is empty
Posted: Wed Mar 31, 2004 2:25 am
by twigletmac
How do $meno0 and $meno1 get set? Are you doing debugging, ie. as you set the variables echoing them out to make sure they have a value?
Mac
Posted: Wed Mar 31, 2004 2:35 am
by Pozor
hello,
for me it seems that the $meno0 and $meno1 arent set!
try it with $meno[0] and $meno[1]
greez Pozor
PS: to get the content of an array use this Format array[$id] //id is the number of the entry or the labeling if you have an assoc_array...
Posted: Wed Mar 31, 2004 2:43 am
by wiedzim
while(ODBC_Fetch_Row($vysledok_vyber_osoba)):
$meno=ODBC_Result($vysledok_vyber_osoba, "ID").ODBC_Result($vysledok_vyber_osoba, "NAZEV").ODBC_Result($vysledok_vyber_osoba, "JMENO");
endwhile;
I only set one $meno from ODBC_RESULT, but if I have a while --- endwhile; echo $meno; I have more records and this records I'd like put into array but I dont know how
ID is a personal numner etc. 4589854236 not a number 1,2,3.4
Posted: Wed Mar 31, 2004 3:08 am
by Pozor
hello,
im working normally with mysql and the funktion for mysql...
while(ODBC_Fetch_Row($vysledok_vyber_osoba)):
$meno=ODBC_Result($vysledok_vyber_osoba, "ID").ODBC_Result($vysledok_vyber_osoba, "NAZEV").ODBC_Result($vysledok_vyber_osoba, "JMENO");
endwhile;
Code: Select all
<?php
$ID = ODBC_Result($vysledok_vyber_osoba, "ID"); //only to simplify the code here (better readability)
while(condition)
{
$meno[] = $ID;
}
or
while(condition)
{
$meno[0][] = $ID;
$meno[1][] = $NAZEV;
$meno[3][] = $JMENO;
}
or
while(condition)
{
$meno[] = $ID.$NAZEV.$JMENO;
}
?>
Here a little skript to work it out when you have a array...
Code: Select all
<?php
$meno[] = 'first';
$meno[] = 'second';
$meno[] = 'third';
$meno[] = 'fourth';
$meno[] = 'fifth';
$output = 'var selectbox = new Array(';
$size = sizeof($meno);
$count = 1;
foreach($meno as $value)
{
if((1 < $count) and ($size >= $count))
{
$output .= ','; //only between the values
}
$output .= "'".$value."'";
$count++;
echo 'count: '.$count.'<br>';
echo 'value: '.$value.'<br>';
}
$output .= ');';
echo '<pre>';
echo $output;
echo '</pre>';
?>
Posted: Wed Mar 31, 2004 3:28 am
by wiedzim
thanks its work better
bye wiedzim