Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>[edit]</p> <p>The selected answer provides a lot of misinformation. I have a problem understanding how making a comparison more strict makes the code work. You'd think just the opposite.</p> <p>PHP Manual:</p> <pre><code>$a == $b Equal TRUE if $a is equal to $b after type juggling. $a === $b Identical TRUE if $a is equal to $b, and they are of the same type. (introduced in PHP 4) </code></pre> <p>I still stand by my answer - I think I was on the right track... but we'll never know.</p> <hr> <p>I believe the problem lies in the <code>else</code> portion of your code.</p> <p>I reformatted the code so I could make sure you didn't have any problems with mismatched braces (you didn't).</p> <p>Try the following code. FYI - I removed $id2 since you weren't using it in the code you supplied.</p> <pre><code>echo "Looking for: {$fbID}\n"; $photos = ''; for( $i=0; $i&lt;=count( $photoData['data'] ); $i++ ) { $id = $photoData['data'][$i]['tags']['data'][0]['id']; echo $id . ($id == $fbID )?' matches':' DOES NOT MATCH' . "&lt;br&gt;\n"; if( $id == $fbID ) { $photos .= "&lt;div style='float:left;margin:25px;'&gt;&lt;a href='crop.php?url=".$photoData['data'][$i]['source']."'&gt;&lt;img src='".$photoData['data'][$i]['picture']."'/&gt;&lt;/a&gt;&lt;/div&gt;"; } else { $photos = 'We cant find any photo tagged with you, go back and select another album'; break; // if you don't break, then you're possibly overwriting anything that's been added in the "true" portion of the if statement. } } </code></pre> <p>[edit]</p> <p>Two loops will help here. There may be a way to refactor this down to a single loop, but this should work.</p> <pre><code>echo "Looking for: {$fbID}&lt;br&gt;\n"; $items = array(); for( $i=0; $i&lt;=count( $photoData['data'] ); $i++ ) { $id = $photoData['data'][$i]['tags']['data'][0]['id']; echo $id . ($id == $fbID )?' matches':' DOES NOT MATCH' . "&lt;br&gt;\n"; if( $id == $fbID ) { $items[] = $photoData['data'][$i]; } } $photos = 'We cant find any photo tagged with you, go back and select another album'; if ( count( $items ) ) { foreach( $items ) { $photos .= '&lt;div style="float:left;margin:25px;"&gt;&lt;a href="crop.php?url=' . $item['source'] . '"&gt;&lt;img src="' . $item['picture'] . '"/&gt;&lt;/a&gt;&lt;/div&gt;'; } } echo $photos; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload