2016-05-14 18 views
-1

Ich habe den folgenden Code:PHP Suche Wert in Array und Echo etwas anderes

$media = $db->query("SELECT * FROM uploaded_photos WHERE user_id='".$profile->id."' LIMIT 20"); 
$picheck = $db->query("SELECT * FROM users WHERE id='".$profile->id."'"); 
$picheck = $picheck->fetch_object(); 

if($media->num_rows == 0) { 
$uploaded_photos = 0; 
} else { 
$uploaded_photos = array(); 
while($photo = $media->fetch_object()) { 
    $photos[] = array('type'=>'uploaded','id' => $photo->id, 'path' => $photo->path); 
} 
} 
//IN A RELATED PHP FILE: 
<?php 
    $c=0; 
    if(!empty($photos)) { 
     for($i = 0; $i < count($photos); $i++) { 
     if($photos[$i]['type'] == 'instagram') { 

     } else { 
      $c++; 
      echo '<div class="col-sm-3 col-md-3 col-lg-3 thumbnail m-5">'; 
      echo '<div class="image-container">'; 
      echo '<img src="'.$system->getDomain().'/uploads/'.$photos[$i]['path'].'" class="img-responsive">'; 
      echo ' 
      <div class="caption"> 
      <h4>'; 
      //HERE IS MY PROBLEM, IF THE PATH OF THE USERS CURRENT PROFILE PHOTO IS THE SAME AS THE PATH OF THE PHOTO DISPLAYED, IT SHOULD ECHO SOMETHING DIFFERENT. 
      if(in_array($picheck->profile_photo, $photos['path'], true)){ echo '<a href="#" class="no-underline pull-left"> <i class="fa fa-exclamation" data-toggle="tooltip" data-placement="right" data-title="Your Profilepicture" placeholder="" data-original-title="" title=""></i> </a>'; 
      } 
      else { echo '<a href="#" onclick="deletePhoto('.$photos[$i]['id'].')" class="no-underline pull-left"> <i class="fa fa-trash" data-toggle="tooltip" data-placement="right" data-title="'.$lang['Delete_Photo'].'" placeholder="" data-original-title="" title=""></i> </a>'; 
      } 
      echo ' 
      <a href="#" onclick="setAsProfilePhoto('.$photos[$i]['id'].')" class="no-underline pull-right"> <i class="fa fa-user" data-toggle="tooltip" data-placement="left" data-title="'.$lang['Profile_Photo'].'" placeholder="" data-original-title="" title=""></i> </a> 
      </h4> 
      </div> 
      '; 
      echo '</div>'; 
      echo '</div>'; 
     } 
     } 
    } 
     if($c==0) { 
     echo 'YOU DONT HAVE ANY PICTURES'; 
    } 
    ?> 

Ich habe hohe und niedrige gesucht, diese zu lösen, ich hoffe jemand kann mir helfen. Ich möchte allen danken, die sich dafür eingesetzt haben, mir vorher zu helfen.

+0

, was Sie tun wollen? klar über Ihre Frage – JYoThI

+0

@RajdeepPaul Ich versuchte, es hat nicht funktioniert – Aurora

+0

@jothi wie gesagt, // Hier ist mein Problem, wenn der Weg der Benutzer aktuelle Profilfoto ist das gleiche wie der Pfad des Fotos angezeigt wird, sollte es ECHO ETWAS UNTERSCHIEDLICH. Wenn also der Profilpfad des Benutzers, der in der db ($ picheck-> profile_picture) gesetzt und gespeichert wird, mit dem Pfad von $ photos ['path'] übereinstimmt, möchte ich ein anderes Symbol und einen anderen Text anzeigen der Tooltipp. – Aurora

Antwort

0

Das Problem, weil diese Linie ist,

if(in_array($picheck->profile_photo, $photos['path'], true)){ ... 
            ^^^^^^^^^^^^^^^ 

Das zweite Argument von in_array() Funktion heißt $photos['path'] falsch ist, weil $photos Array keinen Index path benannt hat.

So ist die richtige Voraussetzung für wenn Block wäre,

if(in_array($picheck->profile_photo, $photos[$i], true)){ ...