开发者

{if...else} how to display an image if a mysql field equals ex.1

开发者 https://www.devze.com 2023-04-10 13:13 出处:网络
i have a question: i have a mysql table that has values such as pages_viewed that increments every time a user accesses a page such as 1,2,3 etc.

i have a question: i have a mysql table that has values such as pages_viewed that increments every time a user accesses a page such as 1,2,3 etc. My question is simple how do i display an image when the field equals or is more than 1?

like

select pages_viewed from table;
if field pages_viewed > 1 than echo images/image.png
开发者_开发知识库

pardon my php i'm not too good at it.

i've been reading here and in other forums but all i can find is drupal or wordpress.


something like

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


Here is everything basically short of database connection, table name, field name.

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

精彩评论

暂无评论...
验证码 换一张
取 消