here is my problem,
i have a php FOR statement, and whatever i do, it goes only ONCE through it... i check my vars into it, and write them to be sure... everything seems ok... BUT it never works...
here is the code ($user is initialized with my session var):
for($i=0;$i<=($size);$i++){
$test = $db->prepare("INSERT INTO `test`(`val`) VALUES ('IN!!')");
$test->execute();
$name = '';
if($i==0){
$name = $db->quote("test");
}else{
$name = $db->quote("number $i");
}
$number = $db->quote($i);
//insert
$query = "INSERT INTO `test`(`name`,`number`) VALUES ($name,$number)";
$insert = $db->prepare($query);
if($insert->execute()){
$id = '';
$get = $db->prepare("SELECT last_insert_id();");
$get->execute();
foreach($get as $myId){
$id = $myId[0];
}
if(!(isRel($db,$user))){
if(!(setIsRel($db,$user,1))){
$error = false;
}
}
if(!(hasRel($db,$etabId))){
if(!(setHasRel($db,$id,1))){
$error = false;
}
}
if(!(buildRelationShip($db,$id,'2'))){
$error = false;
}
if(!(buildRelationShip($db,$id,'3'))){
$error = false;
}
}else{
$error = false;
}
$check1 = '';
$check2 = '';
$check3 = '';
$check4 = '';
if(is_numeric($size)){
$check1 = "OK";
}
if($i<=$size){
$check2 = "OK";
}
$test = $db->prepare("INSERT INTO `test`(`val`) VALUES ('SIZE IS NUMERIC? $check1 -- I SMALLER? $check2')");
$test->execute();
}
ANSWER IS :
IN!! SIZE IS NUMERIC? OK -- I SMALLER? OK
Where am I wrong...?
Thanx for help !
(this PHP code is called from an .ajax request -jquery- but i don't think it has something to do with that because i already did some similar stuff with this...)
The SIZE var is always set to 2 or 3, never less! already checked
EDIT :
Well,
here is the code just before the FOR statement :
function createStages($db,$user,$size){
$error = true;
$size= intval($size);
i don't thing it'll help..
Sounds like your type conversion is getting messed up then. Remove the $size = intval($size), and replace the condition in the for loop with $i <= (int) $size.