<?php
echo '<script language="Javascript" type="text/javascript">';
$i = 0;
foreach ($catArray as $temp){
$name = "v_".$i;
echo ''.$name.' = new Array();';
$i++;
}
$querry = "SELECT * FROM $playlists ORDER BY 'id' ASC";
$selection = mysql_query($querry);
while($rowNum = mysql_fetch_array($selection)) {
$title=$rowNum['name'];
$url=$rowNum['url'];
$cat=$rowNum['categorie'];
$i = 0;
$n = 0;
foreach ($catArray as $temp){
$name = "v_".$i;
if ($temp == $cat){
echo ''.$name.'['.$n.'] = "'.$title.'";';
$n++;
}else {
$n++;
}
$i++;
}
//$n = 0;
}
/*a0 = new Array(
new Array("title", "url"),
new Array("title2", "url"),
new Array("title3", "url")
)*/
echo '</script>';
?>
Basically my script searches a database and an array to populate a javascript array.
This bit:
$i = 0;
foreach ($catArray as $temp){
$name = "v".$i;
echo ''.$name.' = new Array();';
$i++;
}
It gets the number of elements in catArray (Number of categories) and makes an array in javascript for each of them.
This bit:
$querry = "SELECT * FROM $playlists ORDER BY 'id' ASC";
$selection = mysql_query($querry);
while($rowNum = mysql_fetch_array($selection)) {
$title=$rowNum['name'];
$url=$rowNum['url'];
$cat=$rowNum['categorie'];
$i = 0;
$n = 0;
foreach ($catArray as $temp){
$name = "v".$i;
if ($temp == $cat){
Loops trough my playlist database Pulls out the title, url and categorie of each song. If the categorie of the song is the same as a categorie defined inside catArary it should execute this bit:
if ($temp == $cat){
echo ''.$name.'['.$n.'] = "'.$title.'";';
$n++;
}else {
$n++;
}
$i++;
//$n = 0;
}
}
basically it needs to echo a value into my javascript array.
My problem is after the echo has ben made n should increment, and if i increments n should be re-set to 0.
For some reason that does not seem to work...
Can anyone please help out?
Also, when i echo, if i look at the source code of the page all i echo'ed is on the same line, is there a way to insert a line break?
Thanks sooo much for your time i really appriciate it.
~Gabor Szauer