I am trying to compare retrieved json data from a database, and there is a nested if statement within the for loop. The problem is that the 'if' statement is only executing once (when it finds the first record in the database), and then it's being skipped in further iterations.
I am using PHP and MySQL (for the db).
for ($i=0;$i<count($obj['datalist']);$i++){
$name[]=$obj['datalist'][$i]['name'];
if ($name[$i]===$row['user']){ //once it finds the first record, it goes to the 'else' part for the rest of the for loop
//if ($row['user']==$name[$i]){
echo "<p class='testclass'>".$name[$i] ." is in the database! ".$i."<br />";
} else {
echo "<p class='testclass'>". $name[$i] ." is NOT in the database! ".$i."</p>";
}
}
Code can be also found here.
$namearray without any previously defined indexes and then check for it using$ias an index. You sure you shouldn't be doing it like this:$name[$i]=$obj['datalist'][$i]['name'];?