Hi,
I'm having trouble dealing with dynamic arrays for building some javascript functions.
I make the following array:
// Define PHP arrays
$sbu_phparray = array();
$sql = mysql_query("SELECT sbu_id,sbu_name FROM sbu");
while ($row = mysql_fetch_array($sql)) {
$sbu_phparray[$row['sbu_id']] = $row['sbu_name'];
list ($sbu, $name) = $sbu_phparray;
}
With the current contents of table sbu that gives me an array that looks like this:
[1][Digital]
[2][Analog]
[3][IPSG]
From that, I want to produce the following snippet of javascript:
var U=0;L=1;// (U)nlocked & (L)ocked
function doIt(v)
{
if(v==1){unlock(1);lock(2);lock(3);}
if(v==2){lock(1);unlock(2);lock(3);}
if(v==3){lock(1);lock(2);unlock(3);}
}
I've tried something along the lines of:
reset ($sbu_phparray);
while (list ($id, $name) = each ($sbu_phparray)) {
echo "if(_v==$id){unlock($id);";
while (list ($id, $name) = each ($sbu_phparray)) {
echo "lock($id);";
}
echo "}\n";
}
but that only results in me getting the first portion of the function because of the array pointer. I've considered putting in a variable to prev() me back to where I belong in the array but I'm not sure how to go about it properly or if that's the best way to go.
Any ideas?
Thanks!