2013-08-17 13 views
-4

我有以下一段代碼。我想要的只是在td內回顯圖像(在這裏說插入圖像)。任何想法如何做到這一點?在php中如何將圖像輸出到我想要的位置

<?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>"; 
?> 

我想放置圖像的位置「插入圖像在這裏」。任何想法如何做到這一點?

+0

你的問題可能是downvoted,因爲這是在PHP中理解這樣一個基本的東西。不要氣餒它。繼續工作,注意好的答案,很快你會問問題,得到upvoted。 :-) – TecBrat

+0

感謝您的理解朋友... – user2491321

回答

2

那有什麼難的呢?就在圖像路徑分配給一個變量,並且要使用該變量..

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,比現在用在想要你的形象的地方被渲染。

+0

得到語法錯誤,意外','行:$ path_img ='' , ' Profile Image not yet ready! '; – user2491321

+0

@ user2491321使用'.'而不是''' –

+0

非常感謝你....終於開始工作 – user2491321

0

你快到了。

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> 
+0

總是在td中使用這個變量時得到Undefined變量。 – user2491321

+0

然後你的「while」循環沒有運行。檢查應該啓動該循環的條件並從那裏向後排除故障。也就是說,檢查你的數據庫結果。它可能是空的。當你處理它時,請查看PDO而不是「mysql_」。你會很高興你做到了! – TecBrat

+0

這就是我的想法,但認爲它可以成功打印$ comment_user_name和$ comment_user_surname,但不能打印圖像。 – user2491321

相關問題