开发者

Setting up default images in PHP

开发者 https://www.devze.com 2023-02-06 07:10 出处:网络
I am building a social networking site and one functionality is an update status whereby one can update text only as their status or the could update text and an image. As follows:

I am building a social networking site and one functionality is an update status whereby one can update text only as their status or the could update text and an image. As follows:

avatar pic - update text - update image(if image)

avatar pic - update text - default image(if update image not uploaded)

default avatar pic - update text - default image(if avatar and update image not uploaded)

I got the default avatar to work fine but the problem is getting the default update image to show if one does not include an update image.

How do I do this or does anyone have a different solution?

Below is my code:

PHP

<?php
$user_id = $_SESSION['UserSession'];
//query user avatar
$query_avatar_thumb = "SELECT picture_thumb_url FROM picture WHERE user_id='$user_id' AND avatar='1' LIMIT 1";
$avatar_thumb_result = mysql_query($query_avatar_thumb) or die(mysql_error());  
$avatar_thumb = mysql_fetch_assoc($avatar_thumb_result);
$totalRows_avatar_thumb = mysql_num_rows($avatar_thumb_result);

//query username
$query_user_info = "SELECT username FROM users WHERE user_id='$user_id'";
$user_info = mysql_query($query_user_info, $connections) or die(mysql_error());
$row_user_info = mysql_fetch_assoc($user_info);

//query update image
$query_wid_updates = "SELECT update_text, picture_thumb_url FROM wid_updates LEFT JOIN picture ON wid_updates.attached_picture_id = picture.picture_id 
WHERE wid_updates.user_id = '$user_id' ORDER BY wid_updates.update_id DESC";
$wid_updates = mysql_query($query_wid_updates, $connections) or die(mysql_error());
$row_wid_updates = mysql_fetch_assoc($wid_updates);
$totalRows_wid_updates = mysql_num_rows($wid_updates);
?>

MY HTML to show results:

<div id="previous_updates">   
<?php do { ?>                                      
<table width="460" border="0">                     
  <tr>
    <td height="50" width="50">
    <?php 
    if ($totalRows_avatar_thumb==1)
    {
        echo "<a href='index.php?#main_profile_div'><img src='User_Images/$avatar_thumb[picture_thumb_url]' border='0' height='50' width='50'/></a>";
    }
    else
    {
        echo "<a href='index.php?#main_profile_div'><img src='/NNL/Style/Images/default_avatar.png' border='0' height='50' width='50'/></a>";
    }
    ?>
    </td>
    <td width="360" colspan="3" class="overide" id="update_box">&l开发者_运维问答t;div><?php echo $row_wid_updates['update_text']; ?></div></td>
    <td width="50">
    <?php 
    if ($totalRows_wid_updates)
    {
        echo "<a href='#pictures.php'><img src='User_Images/$row_wid_updates[picture_thumb_url]' border='0' height='50' width='50'/></a>";
    }
    else
    {
        echo "<a href='#pictures.php'><img src='/NNL/Style/Images/no_update_image.png' border='0' height='50' width='50'/></a>";
    }
    ?>
    </td>
  </tr>                      
  <tr>
    <td width="50" height="30"></td>
    <td width="120"></td>
    <td width="120" class="ordinary_text_12_green">Comment</td>
    <td width="120"></td>
    <td width="50"></td>
  </tr>
</table> 
<?php } while ($row_wid_updates = mysql_fetch_assoc($wid_updates)); ?>                                                                    
</div> 

My wid_updates table:

update_id   update_text     attached_picture_id     user_id     timestamp
48             b                   NULL                92   2011-01-13 13:22:23
51             c                   61                  92   2011-01-13 18:30:06
52          d                   NULL                92  2011-01-13 18:30:14
53          PPP                 67                  95  2011-01-17 10:28:01
54          PPP                 NULL                95  2011-01-17 10:28:36
55          oo                  68                  95  2011-01-17 10:30:42
56          ll                  69                  95  2011-01-17 10:35:16
57          tt                  70                  95  2011-01-17 10:35:34
58          monday              71                  92  2011-01-17 10:52:59

As of right now, the default images are blank and and I understand why, my if ($totalRows_wid_updates) statement is wrong. How do I fix it. Btw, this is in profile.php where only a users updates are shown, index.php will containing a users plus his pals updates.


<img src="User_Images/<?php echo ($avatar_thumb[picture_thumb_url] != ''? $avatar_thumb[picture_thumb_url]: 'file_name_of_some_default_image.png'); ?>" border='0' height='50' width='50'/>
0

精彩评论

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