Php foreach和或if数组语句

Php foreach和或if数组语句,php,Php,我有一个在列表中显示配置文件的配置文件。如下图所示 用户表格 id | email | full_name | job_title | bio | profile_photo image_id | id | artist_img 图像表格 id | email | full_name | job_title | bio | profile_photo image_id | id | artist_img 代码 <?p

我有一个在列表中显示配置文件的配置文件。如下图所示

用户表格

 id    |  email  |  full_name  |  job_title  | bio |  profile_photo  
 image_id  | id  | artist_img
图像表格

 id    |  email  |  full_name  |  job_title  | bio |  profile_photo  
 image_id  | id  | artist_img
代码

<?php 

$db = dbconnect();
$stmt = $db->prepare('SELECT
 users.email,
 users.full_name,
 users.job_title,
 users.bio,
 users.profile_photo,
 images.id,
 images.artist_img
FROM users
INNER JOIN images ON users.id=images.id GROUP BY images.id');
$stmt->execute();
$result = $stmt->get_result();

while (($row = mysqli_fetch_assoc($result)) != false) {

        $id = $row['id'];        
        $full_name = $row['full_name'];    
        $email = $row['email'];   
        $job_title = $row['job_title'];
        $bio = $row['bio'];
        $ProfilePhoto = $row['profile_photo'];
        $artist_img = $row['artist_img'];    


        if (isset($ProfilePhoto) && ! empty($ProfilePhoto)) {
            $image = "$ProfilePhoto";
        } else {
            $image = "avatar.jpg";
       }

   echo "<div class='container team-wrap'>
           <div class='row'>
             <div class='col-md-6'>
                <img class='img-responsive' src='artist/$image'>
               </div>
                 <div class=\"col-md-6\">
                    <strong>$full_name<br>$job_title</strong>
                      <br>
                      <p>$bio</p>
                      <a href='mailto:$email' class='btn btn-info'>Contact Me</a>
                </div>
             </div>
          </div>

          <div class=\"container space team-wrap\">
           <div class=\"row\">
              <div class=\"col-lg-12\">
                    <div id=\"gallery-slider\" class=\"slider responsive\">
                      <div>";




                          echo"
                        <img src=\"gallery/$artist_img\" alt=\"\"></a>";  




                      echo "</div>
                    </div>
                  <hr>
               </div>
            </div>
        </div>";
    }        
 ?>

是,因为它没有看到变量,因为您将其作为文本进行回显

echo"<img src=\"gallery/$artist_img\" alt=\"\"></a>"; 
您需要将其设置为数组,因为它是一个数组,您必须记住使用“内部”会生成大量数据,也许对您来说,最好运行2次查询,然后再加载图像。内部联接对某些人来说很有用,但很复杂,而且没有任何优势,因为仍然会搜索整个表两次以获得结果 像这样的东西可能适合你

 $artist_img2=array();
//because there are more then one piece of data in it
$artist_img2 = $row['images']; 
//then you need to do another loop to put the data in variables or echo them out     
// in the loop
    //note the row refers to id and not image.id because in the inner array the key will be id 
     $artist_img3=row2['id'];
     echo "<img src=\"gallery/".$artist_img3."\" alt=\"\"></a>"; 
     //end loop
$artist_img2=array();
//因为里面有不止一条数据
$artist_img2=$row['images'];
//然后,您需要执行另一个循环,将数据放入变量中或将其回送出来
//循环中
//注意,该行引用的是id,而不是image.id,因为在内部数组中,键将是id
$artist_img3=第2行['id'];
回声“;
//端环

请共享您的代码。从DB返回数据的代码在哪里?@Gert added content edited它只需在顶部添加$images变量即可检索其他数据这是相同的结果艺术家图像不是个人资料图片艺术家上传的图像您的版本提供相同的结果时,仅在库中显示1个图像数据库中有5个,如果您感到困惑,请在发布时了解您自己的代码。我可以在5分钟内为此编写一个完整的工作代码,但这个论坛不是为其他人编写代码,而是解决错误
$artist_img = $row['artist_img'];
 $artist_img2=array();
//because there are more then one piece of data in it
$artist_img2 = $row['images']; 
//then you need to do another loop to put the data in variables or echo them out     
// in the loop
    //note the row refers to id and not image.id because in the inner array the key will be id 
     $artist_img3=row2['id'];
     echo "<img src=\"gallery/".$artist_img3."\" alt=\"\"></a>"; 
     //end loop