Page 1 of 1
FOR loop
Posted: Wed Jul 27, 2005 10:18 pm
by S_henry
This is part of my code in javascript function:
Code: Select all
'<?php echo $i = 1; ?>'
var j = 1;
for(var a=1; a<='<?php echo $x;?>'; a++){
alert('<?php echo $i;?>');
alert(j);
'<?php $i = $i + 1; ?>'
j = j + 1;
}
In this loop, the result is 'j' value will increase each time base on the value of '$x'. The problem is value for '$i' is not increase, the value is still the same (ie. 1) until looping was finished. Anybody know how to solve this problem?
Posted: Wed Jul 27, 2005 10:29 pm
by Burrito
server side php is...client side js is. Mix the two like you're trying you can not.
increment $i will not on the client side.
the code the client will receive this is:
Code: Select all
1
var j = 1;
for(var a=1; a<={whatever $x is on the server side say 3 for this example} 3; a++){
alert('1');
alert(j);
''
j = j + 1;
}
Posted: Thu Jul 28, 2005 1:33 am
by S_henry
Actually i want to use index array in that loop. Here is the example (code in javascript):
Code: Select all
'<?php
$query = "e;SELECT studName FROM Student"e;;
$result = mysql_query ($query, $db)
or die ("e;Query failed"e;);
$b=1;
while ($point=mysql_fetch_object ($result)) {
$snї$b] = $point->studName;
$b=$b+1;
}
?>'
'<?php echo $i = 1; ?>'
var j = 1;
for(var a=1; a<='<?php echo $x;?>'; a++){
alert('<?php echo $snї$i];?>');
alert('<?php echo $i;?>');
alert(j);
'<?php $i = $i + 1; ?>'
j = j + 1;
}
So anybody has any idea to solve this problem?