2013-03-27 34 views
0

我想根據存儲在數據庫中的值在我的頁面上顯示從1到5的星星。我正在嘗試編寫PHP代碼,用於在HTML標記中回顯mySQL數據庫中的數據。我不知道我的代碼是正確錯誤。我通過一個while循環運行它並調用許多HTML標記中的數據。我已將圖像存儲在我的電腦中的文件夾圖像中,分別爲1stars.png,2stars.png,3stars.png,4stars.png和5stars.png。以下是我的代碼。根據數據庫中的值將圖像從1更改爲5

<?php 
    $query = mysql_query("select * from printers where printers_id='1';"); 
    while ($row = mysql_fetch_array($query)) 
    { 
?> 
     <table width="281" border="0" style="margin-left:40px; margin-top:10px;" cellspacing="20"> 
     <tr> 
      <td class="table_text_left"><figure>Value for money:&nbsp;&nbsp;&nbsp;&nbsp;<img src=images/"<?php echo $row['Value_For_Money'];?>".stars.png alt="5 stars" /></figure></td> 
     </tr> 
     </table> 
<?php 
} 
?> 
+0

正確寫我們的代碼 – 2013-03-27 09:59:27

+0

那麼什麼不對的地方,你有沒有收到一些錯誤訊息? – 2013-03-27 10:01:24

+0

我收到一張破碎的圖像。我只想知道語法中是否有錯誤? – 2013-03-27 10:02:08

回答

0

我已經編輯Coramba的答案,對我來說,現在工作得很好。謝謝coramba。

img src="images/<?php echo $row['Value_For_Money']; ?>.stars.png" alt="5 stars" /> 

<img src="images/<?php echo $row['Value_For_Money']; ?>stars.png" alt="5 stars" /> 
1

這都是關於報價。更改

<img src=images/"<?php echo $row['Value_For_Money']; ?>".stars.png alt="5 stars" /> 

<img src="images/<?php echo $row['Value_For_Money']; ?>.stars.png" alt="5 stars" /> 
+0

嗨Coramba,對不起,它不起作用 – 2013-03-27 10:05:27

+0

@ user2148257,你見過我的第二次編輯?第一個報價也是錯誤的地方。我注意到只有在發佈答案後。現在檢查它,如果它仍然不能確定發佈你的'html源代碼'在這裏。 – 2013-03-27 10:09:03

+0

嗨Coramba,我已經得到了答案。我編輯了你的答案。剛剛在stars.png之前刪除了concatination符號,它對我來說工作正常。我在下面發佈了正確的答案。感謝您向我展示正確答案的方法。非常感謝。 – 2013-03-27 10:17:08

相關問題