2013-02-22 57 views
0

我一直在试图显示图像到heredoc它不能工作,我得到没有错误 但是,如果我展示他们如果heredoc他们很好地显示。可能是什么问题? 对于任何帮助,我将不胜感激。 这里是代码,我确实在heredoc和out中显示了两次图像,以便您清楚地看到。如何将数据库中的图片显示到heredoc?

<?Php 
$target = "image_uploads/"; 
$image_name = (isset($_POST['image_name'])); 
$query ="select * from 
tish_user inner join tish_images 
on tish_user.user_id = tish_images.user_id 
WHERE tish_images.prof_image = 1"; 
    $result= $con->prepare($query); 
    $result->execute(); 

$table = <<<ENDHTML 
<div style ="text-align:center;"> 
<h2>Client Review Software</h2> 
<table id ="heredoc" border ="0" cellpaddinig="2" cellspacing="2" style = "width:100%" ; 
margin-left:auto; margin-right: auto;> 
<tr> 
<th>Name</th> 
<th>Last Name</th> 
<th>Ref No</th> 
<th>Cell</th> 
<th>Picture</th> 
</tr> 
ENDHTML; 

while($row = $result->fetch(PDO::FETCH_ASSOC)){ 
    $date_created = $row['date_created']; 
     $user_id = $row['user_id']; 
     $username = $row['username']; 

     $image_id = $row['image_id']; 
     #this is the Tannery operator to replace a pic when an id do not have one 
$photo = ($row['image_name']== null)? "me.png":$row['image_name']; 
#display image 
      # I removed this line up to here 
     echo '<img src="'.$target.$photo.'" width="100" height="100">'; 



$table .= <<<ENDINFO 
<tr> 
<td><a href ="client_details.php?user_id=$user_id">$username </a></td> 
<td>$image_id</td> 
<td></td> 
<td>c</td> 
<td><img src="'.$target.$photo.'" width="100" height="100"> 
</td> 
</tr> 
ENDINFO; 
} 
    $table .= <<<ENDHTML 
</table> 
<p>$numrows"Clients</p> 
</div> 
ENDHTML; 
echo $table; 
?> 

回答

1
<td><img src="'.$target.$photo.'" width="100" height="100"> 

在heredoc中的这条线对我没有意义。您应该直接使用字符串中的变量,不要使用单引号和连字点。

像这样:

<td><img src="$target$photo" width="100" height="100"> 

但是,因为你要经过对方右印两个变量,你可能需要使用大的语法:

<td><img src="{$target}{$photo}" width="100" height="100"> 

你可以阅读更多关于卷曲语法 here。你基本上用大括号({})来包装变量,以帮助PHP了解变量名称的开始和结束位置。

+0

我真的很感激 – humphrey 2013-02-22 09:31:42

2

使用heredoc,并在不显示图像的浏览器中查看其源

的图片src会是这样<img src="'.../images/.me.png.'" ...这是不对的,你可以看到单引号和额外费用。对于IMG SRC

双引号内(期号)试试这个代码

$table .= <<<ENDINFO 
<tr> 
<td><a href ="client_details.php?user_id=$user_id">$username </a></td> 
<td>$image_id</td> 
<td></td> 
<td>c</td> 
<td><img src="{$target}{$photo}" width="100" height="100"> 
</td> 
</tr> 
ENDINFO; 
} 

所以

<img src="'.$target.$photo.'" width="100" height="100"> 

<img src="{$target}{$photo}" width="100" height="100"> 

让我知道这样做是否解决,请总是检查浏览器的view source选项的HTML源代码,以查看打印内容

+0

我很高兴你们帮我解决了它。 – humphrey 2013-02-22 09:30:34

0

这样做,并显示你想要的任何地方声明的变量。 也删除这里面的heredoc放$ pic。

$pic = '<img src="'.$target.$photo.'" width="50" height="50">'; 
echo $pic ; 
+1

好的我确实使用过这个工作,但我不知道它是否最好 – humphrey 2013-02-22 09:31:26

相关问题