Jump to content

Change default image on script


hoponhiggo

Recommended Posts

Hi Guys

 

Im using a facebook style wall post script, which i have customised a fair bit, but the one thing that is causing me a headache is the 'avatar image' part.

 

In the script, there is a file called functions.php. When a user posts a message, it is this file that saves the data to the database and is initially displayed on the page along with the users name and picture etc. When the page is refreshed, a seperate file called loadcomments.php recalls the data and then displays it.

 

I have managed to change the loadcomments.php to display the profile picture of the user that left the comment using

 

<?php
//to display image from source
$dir = "prof_pics";

$sql = "SELECT prof_pic FROM users WHERE users.uid = $uid";
$res = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($res) == 0) die("Username not found in database.");

$row = mysql_fetch_array($res);
echo "<img src='$dir/{$row['prof_pic']}' width='50' height='50'><br>";

?>

 

So when the page is refreshed, the picture of the person who left the message is displayed

 

I cant however figure out how to use this in the functions.php file. Currently, until the page is refreshed, it shows a crappy default picture.

 

Can anybody please help. The complete functions.php file is:

 

<?php
//Srinivas Tamada http://9lessons.info
//Wall_Updates

class Wall_Updates {


    
     // Updates   	
  public function Updates($uid) 
{
    $query = mysql_query("SELECT M.msg_id, M.uid_fk, M.message, M.created, U.username FROM messages M, users U  WHERE M.uid_fk=U.uid and M.uid_fk='$uid' order by M.msg_id desc ") or die(mysql_error());
         while($row=mysql_fetch_array($query))
	$data[]=$row;
    return $data;

    }
//Comments
   public function Comments($msg_id) 
{
    $query = mysql_query("SELECT C.com_id, C.uid_fk, C.comment, C.created, U.username FROM comments C, users U WHERE C.uid_fk=U.uid and C.msg_id_fk='$msg_id' order by C.com_id asc ") or die(mysql_error());
   while($row=mysql_fetch_array($query))
    $data[]=$row;
        if(!empty($data))
	{
       return $data;
         }
}

//Avatar Image
public function Gravatar($uid) 
{
    $query = mysql_query("SELECT email FROM `users` WHERE uid='$uid'") or die(mysql_error());
   $row=mysql_fetch_array($query);
   if(!empty($row))
   {
    $email=$row['email'];
        $lowercase = strtolower($email);
        $imagecode = md5( $lowercase );
	$data="http://www.gravatar.com/avatar.php?gravatar_id=$imagecode";
	return $data;
         }
	 else
	 {
	 $data="default.jpg";
	return $data;
	 }
}

//Insert Update
public function Insert_Update($uid, $update) 
{
$update=htmlentities($update);
   $time=time();
   $ip=$_SERVER['REMOTE_ADDR'];
        $query = mysql_query("SELECT msg_id,message FROM `messages` WHERE uid_fk='$uid' order by msg_id desc limit 1") or die(mysql_error());
        $result = mysql_fetch_array($query);

        if ($update!=$result['message']) {
            $query = mysql_query("INSERT INTO `messages` (message, uid_fk, ip,created) VALUES ('$update', '$uid', '$ip','$time')") or die(mysql_error());
            $newquery = mysql_query("SELECT M.msg_id, M.uid_fk, M.message, M.created, U.username FROM messages M, users U where M.uid_fk=U.uid and M.uid_fk='$uid' order by M.msg_id desc limit 1 ");
            $result = mysql_fetch_array($newquery);
		 return $result;
        } 
	else
	{
			 return false;
	}

       
    }

//Delete update
	public function Delete_Update($uid, $msg_id) 
{
    $query = mysql_query("DELETE FROM `comments` WHERE msg_id_fk = '$msg_id' ") or die(mysql_error());
        $query = mysql_query("DELETE FROM `messages` WHERE msg_id = '$msg_id' and uid_fk='$uid'") or die(mysql_error());
        return true;
      	       
    }

//Insert Comments
public function Insert_Comment($uid,$msg_id,$comment) 
{
$comment=htmlentities($comment);
   	    $time=time();
   $ip=$_SERVER['REMOTE_ADDR'];
        $query = mysql_query("SELECT com_id,comment FROM `comments` WHERE uid_fk='$uid' and msg_id_fk='$msg_id' order by com_id desc limit 1 ") or die(mysql_error());
        $result = mysql_fetch_array($query);
    
	if ($comment!=$result['comment']) {
            $query = mysql_query("INSERT INTO `comments` (comment, uid_fk,msg_id_fk,ip,created) VALUES ('$comment', '$uid','$msg_id', '$ip','$time')") or die(mysql_error());
            $newquery = mysql_query("SELECT C.com_id, C.uid_fk, C.comment, C.msg_id_fk, C.created, U.username FROM comments C, users U where C.uid_fk=U.uid and C.uid_fk='$uid' and C.msg_id_fk='$msg_id' order by C.com_id desc limit 1 ");
            $result = mysql_fetch_array($newquery);
         
	   return $result;
        } 
	else
	{
	return false;
	}
       
    }

//Delete Comments
	public function Delete_Comment($uid, $com_id) 
{
    $query = mysql_query("DELETE FROM `comments` WHERE uid_fk='$uid' and com_id='$com_id'") or die(mysql_error());
        return true;
      	       
    }

    

}

?>

 

Its the //avatar image bit that needs to be changed i think!

Link to comment
https://forums.phpfreaks.com/topic/240225-change-default-image-on-script/
Share on other sites

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.