2011-10-05 59 views
-1

我有一個問題: 我有一個mysql表格,其值爲pages_viewed,每增加一次用戶訪問頁面作爲1,2,3等 我的問題很簡單,當字段等於或大於1時,如何顯示圖像?{if ... else}如果mysql字段等於ex.1時如何顯示圖像

select pages_viewed from table; 
if field pages_viewed > 1 than echo images/image.png 

原諒我的PHP我不是它太美好了。

我一直在這裏和其他論壇閱讀,但我可以找到的所有是Drupal或WordPress的。

+0

愛你如何給pages_viewed如何增加一個例子! – miki

+0

@miki,我盡了全力。 – user964535

回答

0

header('Content-Type: image/png') 
echo file_get_contents(images/image.png) 
+0

,我需要這是有條件的,如果該字段等於或大於ex.1而不是從我的圖像文件夾中顯示圖像。我已經在使用標題。 – user964535

0

這裏是一切基本上短的數據庫連接,表名,字段名。

mysql_connect("localhost", "mysql_user", "mysql_password") or die("Could not connect: " . mysql_error()); 
mysql_select_db("mydb"); 

$result = mysql_query("select * from table"); 

while ($row = mysql_fetch_array($result, MYSQL_NUM)) { 
    # Any other code to post the page information 
    if($row['pages_viewed'] > 0) echo "<img src='images/image.png' />"; 
    # Any other code to post the page information 
}