在php中如何将图像输出到我想要的位置


in php how to output image to position that I want

我有以下一段代码。我只想在td中回显图像(上面写着在这里插入图像)。知道怎么做吗?

<?php
$personal_1 = mysql_query("SELECT `user_id`, `name`, `surname`, `profile` FROM `users` WHERE `user_id`='{$row['user']}' ");
while ($run_personal_1= mysql_fetch_assoc($personal_1)) {
    $comment_user_id = $run_personal_1['user_id'];
    $comment_user_name = $run_personal_1['name'];
    $comment_user_surname = $run_personal_1['surname'];
    $comment_user_profile = $run_personal_1['profile'];
  $profile_data     = user_data($comment_user_id,'name','surname','email','profile');
  if(!($profile_data['profile']==NULL)){
    echo '<img src="', $profile_data['profile'], '" alt="' ,  '  Profile Image not yet ready!  ">'; 
  }else     
    echo'<img src="img/photo.jpg"/>'; 
}

$comments .= "<table border='1'> <td>   insert image here   </td> <td> $comment_user_surname   $comment_user_name </td></table>"; 
?>

我想把图片放在位置"插入图片在这里"。知道怎么做吗?

那么这里面有什么困难呢?只需将图像路径分配给一个变量,并在需要的地方使用该变量即可。

if(!($profile_data['profile']==NULL)){
    $path_img = '<img src="'.$profile_data['profile'].'" alt="'.'  Profile Image not yet ready!  ">'; 
  }else     
    $path_img ='<img src="img/photo.jpg"/>'; 
}

$comments .= "<table border='1'> <td>   $path_img   </td> <td> $comment_user_surname   $comment_user_name </td></table>"; 

在上面的代码中,我将路径存储在$path_img中,然后在您希望渲染图像的位置使用。

您就快到了。

  if(!($profile_data['profile']==NULL)){
    $img= '<img src="', $profile_data['profile']. '" alt="' .  '  Profile Image not yet ready!  ">'; 
  }else     
    $img='<img src="img/photo.jpg"/>'; 
}

$comments .= "<table border='1'> <td>".$img."</td>