2013-02-22 59 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

相關問題