Hi Folks,
Can someone tell me how to create a dynamic array from a MySql query? I'm trying to create a slideshow mixing PHP and Javascript and am having trouble getting my mind around plugging my PHP variable into Javascript.
I can create a slideshow using strictly Javascript, hard-coding my images, but I need to pull the images from a database query. Here is my SQL:
$sql = "SELECT image WHERE ID=$ID"; <--- can be 4-8 rows
$result = mysql_query($sql);
while ($myrow = mysql_fetch_row($result)) {
$bad = ("../");
$title = $myrow[0];
$comments = $myrow[1];
$image = str_replace($bad,"",$myrow[2]);
}
How do I take this query and put an array in the this Javascript:
<SCRIPT Language="JavaScript">
<!--
var picture = new Array("PHP ARRAY") <---- ???
var picNumber=1
var numberofPics = picture.length
function previousPicture(){
if(picNumber > 1){
picNumber--
}
document.myPicture.src=picture[picNumber-1]
}
function nextPicture(){
if(picNumber < numberofPics){
picNumber++
}
document.myPicture.src=picture[picNumber-1]
}
//-->
</script>
Any help in merging these two languages will be greatly appreciated. I will continue my search; Javascript just plain confuses me.
Thanks! 🙂