php - Displaying user avatar or default avatar on search -


im having problem php search script. i'm building social networking site 1 can search user, event or club. search results display user avatar thumb or default thumb if none has been uploaded. im testing on localhost. user avatar's stored in user_images (c:\wamp\www\nnl\user_images)folder while default avatar stored in c:\wamp\www\nnl\style\images\default_avatar.png.

the following php code:

<?php while ($row_user = mysql_fetch_assoc($user)) {   echo "\n<table width='500' border='0'>";   echo "\n\t<tr>";   echo "<td width='50' height='50' align='center' valign='middle'><a href='user_view.php?user_id=".$row_user['user_id']."'>   <img src=user_images/$row_user[picture_thumb_url] !=''? $row_user[picture_thumb_url]: '../style/images/default_avatar.png'   border='0' height='50' width='50'/></a></td>";   echo "<td width='140' class='ordinary_text_12'>" .$row_user['user_first_name']. "</td>";   echo "<td width='140' class='ordinary_text_12'>" .$row_user['user_last_name']. "</td>";   echo "<td width='140' class='ordinary_text_12'>" .$row_user['username']. "</td>";   echo "<td width='30'><a class='text_12_link_green' href='user_view.php?user_id=".$row_user['user_id']."'>view</a></td>";   echo "\n\t</tr>";   echo "\n</table>"; } ?> <?php while ($row_event = mysql_fetch_assoc($event)) {   echo "\n<table width='500' border='0'>";   echo "\n\t<tr>";   echo "<td width='50' height='50' align='center' valign='middle'><a href='#table_index.php'>   <img src='images/$row_event[event_thumb_url]' border='0' height='50' width='50'/></a></td>";   echo "<td width='140' class='ordinary_text_12'>" .$row_event['event_name']. "</td>";   echo "<td width='140' class='ordinary_text_12'>" .$row_event['event_venue']. "</td>";   echo "<td width='140' class='ordinary_text_12'>" .$row_event['event_date']. "</td>";   echo "<td width='30'><a class='text_12_link_green' href='#user_view.php?user_id=".$row_user['username']."'>view</a></td>";   echo "\n\t</tr>";   echo "\n</table>"; } ?> <?php while ($row_establishment = mysql_fetch_assoc($establishment)) {   echo "\n<table width='500' border='0'>";   echo "\n\t<tr>";   echo "<td width='50' height='50' align='center' valign='middle'><a href='#table_index.php'>   <img src='establishment_images/$row_establishment[establishment_thumb_url]' border='0' height='50' width='50'/></a></td>";   echo "<td width='140' class='ordinary_text_12'>" .$row_establishment['establishment_name']. "</td>";   echo "<td width='140' class='ordinary_text_12'>" .$row_establishment['location_name']. "</td>";   echo "<td width='140' class='ordinary_text_12'>" .$row_establishment['establishment_pricing']. "</td>";   echo "<td width='30'><a class='text_12_link_green' href='#user_view.php?user_id=".$row_user['username']."'>view</a></td>";   echo "\n\t</tr>";   echo "\n</table>"; } ?> 

the problem in $row_user while loop im trying echo $row_user thumb. right now, if user has avatar, displays image, returns no image @ if user has no avatar. going wrong?

you can although it's not readable.

echo "<td width='50' height='50' align='center' valign='middle'><a href='user_view.php?user_id=".$row_user['user_id']."'>   <img src=user_images/" . ( $row_user['picture_thumb_url'] != '' ? $row_user['picture_thumb_url'] : '../style/images/default_avatar.png' ) . " border='0' height='50' width='50'/></a></td>"; 

you're best of doing conditional beforehand echo variable:

updated:

$thumbnail = $row_user['picture_thumb_url'] != '' ? $row_user['picture_thumb_url'] : '../style/images/default_avatar.png';  echo "<td width='50' height='50' align='center' valign='middle'><a href='user_view.php?user_id=".$row_user['user_id']."'>       <img src=user_images/$thumbnail border='0' height='50' width='50'/></a></td>"; 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -