muro tipo fb

searedone

Utente Attivo
11 Giu 2010
508
0
0
Ciao a tutti,
ho uno script tipo fb che ho adattato al mio sito, e tutto funziona correttamente, pero nella classee che vi posto secondo me c'è un problema di correlazione tra gli utenti, mi psiego meglio:

Se pippo scrive nel muro ciao paperina, i mex sono salvati nel db, ma li vede solo paperino, se si logga paperina vede solo i mex che ha postato paperina...

io vorrei che tutti quelli loggati possano vedere i post altrui e commentarli a vicenda.. chi mi puo' aiutare a capire perchè ??

Cavolo ho risolto tutto, ma questo non mi riesce proprio :incazz2:


PHP:
<?php 


class Wall_Updates { 

public $perpage = 10; // Uploads perpage 
     

     
     // Updates        
      public function Updates($id,$lastid)  
    { 
      // More Button 
       $morequery=""; 
        if($lastid) 
        $morequery=" and M.msg_id<'".$lastid."' "; 
       // More Button End 
        
        $query = mysql_query("SELECT M.msg_id, M.id_fk, M.message, M.created, U.username,M.uploads FROM messages M, users U  WHERE M.id_fk=U.id and M.id_fk='$id' $morequery order by M.msg_id desc limit " .$this->perpage) or die(mysql_error()); 
         
         while($row=mysql_fetch_array($query)) 
        $data[]=$row; 
        return $data; 
         
    } 
         // Updates        
      public function Total_Updates($id)  
    { 
             
        $query = mysql_query("SELECT M.msg_id, M.id_fk, M.message, M.created, U.username,M.uploads FROM messages M, users U  WHERE M.id_fk=U.id and M.id_fk='$id' $morequery order by M.msg_id ") or die(mysql_error()); 
        $data=mysql_num_rows($query); 
        return $data; 
         
    } 
     
    //Comments 
       public function Comments($msg_id,$second_count)  
    { 
    $query=''; 
      if($second_count) 
      $query="limit $second_count,2"; 
        $query = mysql_query("SELECT C.com_id, C.id_fk, C.comment, C.created, U.username FROM comments C, users U WHERE C.id_fk=U.id and C.msg_id_fk='$msg_id' order by C.com_id asc $query") or die(mysql_error()); 
       while($row=mysql_fetch_array($query)) 
        $data[]=$row; 
        if(!empty($data)) 
        { 
       return $data; 
         } 
    } 
     
     
    //Avatar Image 
    //From database 
     public function Profile_Pic($id)  
    { 
        $query = mysql_query("SELECT profile_pic FROM `users` WHERE id='$id'") or die(mysql_error()); 
       $row=mysql_fetch_array($query); 
       if(!empty($row['profile_pic'])) 
       { 
        $profile_pic_path=$base_url.'profile_pic/'; 
        $data=    $profile_pic_path.$row['profile_pic']; 
        return $data; 
         } 
         else 
         { 
         $data="icons/default.jpg"; 
        return $data; 
         } 
    } 
    //  Gravatar Image 
    public function Gravatar($id)  
    { 
        $query = mysql_query("SELECT email FROM `users` WHERE id='$id'") 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($id, $update,$uploads)  
    { 
    $update=mysql_real_escape_string($update); 
      $time=time(); 
       $ip=$_SERVER['REMOTE_ADDR']; 
        $query = mysql_query("SELECT msg_id,message FROM `messages` WHERE id_fk='$id' order by msg_id desc limit 1") or die(mysql_error()); 
        $result = mysql_fetch_array($query); 
         
        if ($update!=$result['message']) { 
          $uploads_array=explode(',',$uploads); 
          $uploads=implode(',',array_unique($uploads_array)); 
            $query = mysql_query("INSERT INTO `messages` (message, id_fk, ip,created,uploads) VALUES (N'$update', '$id', '$ip','$time','$uploads')") or die(mysql_error()); 
            $newquery = mysql_query("SELECT M.msg_id, M.id_fk, M.message, M.created, U.username FROM messages M, users U where M.id_fk=U.id and M.id_fk='$id' order by M.msg_id desc limit 1 "); 
            $result = mysql_fetch_array($newquery); 
         
             return $result; 
        }  
        else 
        { 
                 return false; 
        } 
         
        
    } 
     
    //Delete update 
        public function Delete_Update($id, $msg_id)  
    { 
        $query = mysql_query("DELETE FROM `comments` WHERE msg_id_fk = '$msg_id' and id_fk='$id' ") or die(mysql_error()); 
        $query = mysql_query("DELETE FROM `messages` WHERE msg_id = '$msg_id' and id_fk='$id'") or die(mysql_error()); 
        return true; 
                  
    } 
     
        //Image Upload 
        public function Image_Upload($id, $image)  
    { 
    //Base64 encoding 
    $path="uploads/"; 
           $img_src = $path.$image; 
     $imgbinary = fread(fopen($img_src, "r"), filesize($img_src)); 
     $img_base = base64_encode($imgbinary); 
     $ids = 0; 
        $query = mysql_query("insert into user_uploads (image_path,id_fk)values('$image' ,'$id')") or die(mysql_error()); 
        $ids = mysql_insert_id(); 
        return $ids; 
    } 
     
            //get Image Upload 
        public function Get_Upload_Image($id,$image)  
    {     
        if($image) 
        { 
          $query = mysql_query("select id,image_path from user_uploads where image_path='$image'") or die(mysql_error()); 
        } 
        else 
        { 
           $query = mysql_query("select id,image_path from user_uploads where id_fk='$id' order by id desc ") or die(mysql_error()); 
        } 
       
         $result = mysql_fetch_array($query); 
         
        return $result; 
    } 
     
        //Id Image Upload 
        public function Get_Upload_Image_Id($id)  
    {     
        $query = mysql_query("select image_path from user_uploads where id='$id'") or die(mysql_error()); 
         $result = mysql_fetch_array($query); 
         
        return $result; 
    } 
     
    //Insert Comments 
    public function Insert_Comment($id,$msg_id,$comment)  
    { 
    $comment=mysql_real_escape_string($comment); 
     
               $time=time(); 
       $ip=$_SERVER['REMOTE_ADDR']; 
        $query = mysql_query("SELECT com_id,comment FROM `comments` WHERE id_fk='$id' 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, id_fk,msg_id_fk,ip,created) VALUES (N'$comment', '$id','$msg_id', '$ip','$time')") or die(mysql_error()); 
            $newquery = mysql_query("SELECT C.com_id, C.id_fk, C.comment, C.msg_id_fk, C.created, U.username FROM comments C, users U where C.id_fk=U.id and C.id_fk='$id' 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($id, $com_id)  
    { 
        $query = mysql_query("DELETE FROM `comments` WHERE id_fk='$id' and com_id='$com_id'") or die(mysql_error()); 
        return true; 
                  
    } 

     

} 

?>
 
Allora ho ripreso un vecchio script e ho modificato cosi .....

PHP:
class Wall_Updates {

public $perpage = 10; // Uploads perpage
    

	
     // Updates   	
	  public function Updates($id,$lastid) 
	{
	  // More Button
       $morequery="";
		if($lastid)
		$morequery=" and M.msg_id<'".$lastid."' ";
	   // More Button End
	   
	    $query = mysql_query("SELECT M.msg_id, M.id_fk, M.message, M.created, U.username,M.uploads FROM messages M, users U WHERE M.id_fk=U.id and M.id_fk='$id' $morequery OR M.id_fk=$id IN (SELECT user_1 FROM relationship AS r WHERE r.user_2 = '$uid' AND r.amico = 'S') OR M.id_fk IN (SELECT user_2 FROM relationship AS r WHERE r.user_1 = '$id' AND r.amico = 'S') order by M.msg_id desc limit " .$this->perpage) or die(mysql_error());
		
         while($row=mysql_fetch_array($query))
		$data[]=$row;
	    return $data;
		
    }

Ma mi posta i risultati di tutti e non solo di quelli in qui sono amico ....

posto la tabella relationship vediamo se qualcuno puo' aiutarmi ... vi prego sto impazzendo .....

PHP:
-- phpMyAdmin SQL Dump
-- version 2.11.9.6
-- http://www.phpmyadmin.net
--
-- Host: localhost:3306
-- Generato il: 17 Mar, 2013 at 05:31 PM
-- Versione MySQL: 5.1.58
-- Versione PHP: 5.2.6

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

--
-- Database: `verdemoneta`
--

-- --------------------------------------------------------

--
-- Struttura della tabella `relationship`
--

CREATE TABLE IF NOT EXISTS `relationship` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `user_1` bigint(20) NOT NULL,
  `user_2` bigint(20) NOT NULL,
  `amico` enum('S','N') NOT NULL DEFAULT 'N',
  `user_id` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=71 ;

--
-- Dump dei dati per la tabella `relationship`
--

INSERT INTO `relationship` (`id`, `user_1`, `user_2`, `amico`, `user_id`) VALUES
(12, 106, 79, 'S', 0),
(9, 79, 106, 'S', 0),
(70, 102, 106, 'S', 0);
 
Ciao, non sono un grande esperto di sql, ma personalmente proverei a unire le varie tabelle con i JOIN, per esempio:

SELECT * FROM message LEFT JOIN users ON message.uid = users.id FULL JOIN relationship ON users.id = relationship.user_1 WHERE relationship.user_2 = ID_UTENTE AND relationship.amico = 'S'

la query è a solo scopo esplicativo.
Spero di essermi spiegato, perchè alle 4 di notte sono un po fuso.
Buona notte
 

Discussioni simili