Jump to content

Using if/else statments to fetch avatar from mysql db


K3nnnn

Recommended Posts

i want to fetch a value from my user database table for the current logged in user. Then using the conditions, if $X equals 0 echo the default avatar location, else get the location from avatar_loc field and echo the avatar.

 

heres what ive come up with:

/* Avatar */
echo "<img src='../../../img/icons/avatar_icon.png' /> ";
echo " <b>Avatar:</b>";
require_once('includes/DbConnector.php');

$connector = new DbConnector();

// Execute the query to find if user has an avatar, echo uploaded avatar if there is one in DB, if not load default.
$result = $connector->query('SELECT avatar, FROM users WHERE ID = $session->username ');


echo $result;
if 
($result==1){
	echo "test works";
}

else
   echo " <img src='../../../img/icons/default_avitar.gif' width='32' height='32' />";

im going wrong somewhere but i cant pin point it

 

the output at the moment is the default avatar even ifthere is a 1  in the avatar field

 

thanks for taking time to read this

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.