Estrazione Username

Stato
Chiusa ad ulteriori risposte.
così il seguente errore

PHP:
	    $query = mysql_query("SELECT M.msg_id, M.uid_fk, M.message, M.created, U.username, M.uploads, R.user_1, R.user_2 FROM messages M, users U, relationship AS R  WHERE M.uid_fk = U.uid AND M.uid_fk='$uid' IN r.user_2 = '$uid' AND r.amico = 'S' AND r.user_1 = '$uid' AND r.amico = 'S' '$morequery' order by M.msg_id desc limit " .$this->perpage) or die(mysql_error());

//questo mettendo IN  ( IN r.user_2 = '$uid' AND r.amico = 'S' AND r.user_1 = '$uid' AN )

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'r.user_2 = '61' AND r.amico = 'S' AND r.user_1 = '61' AND r.amico = 'S' '' order' at line 1

così invece questo mex ....

PHP:
	    $query = mysql_query("SELECT M.msg_id, M.uid_fk, M.message, M.created, U.username, M.uploads, R.user_1, R.user_2 FROM messages M, users U, relationship AS R  WHERE M.uid_fk = U.uid AND M.uid_fk='$uid' OR r.user_2 = '$uid' AND r.amico = 'S' AND r.user_1 = '$uid' AND r.amico = 'S' '$morequery' order by M.msg_id desc limit " .$this->perpage) or die(mysql_error());

// cosi me lo da mettendo OR o AND ( OR r.user_2 = '$uid' AND r.amico = 'S' AND )

Unknown column 'r.user_2' in 'where clause'

Cavolo secondo me siamo vicini :)
 
così invece mi restituisce tutto corretto ma non mi prende la relazione con la tabella relationship :(

PHP:
class Wall_Updates {

public $perpage = 10; // Uploads perpage
    

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

il vardump restituisce questo

resource(9) of type (mysql result) resource(10) of type (mysql result)

secondo me se mi potete aiutare bisogna solo capire come mettere l'interrogazione alla tanella relatiosìnship e basta senza modificare altro ...
 
Prova e riprova prova e riprova :( che vitaccia ...........
ALLORA COSI FUNZIONA DIREI TUTTO .. SE NON CHE:


A DIFFERENZA DI PRIMA CHE SE FACEVO REFRESH MI RITROVAVO LO STESSO POST Più VOLTE ORA NON SUCCEDE PIùùùù :)))))

FIGO..

PERO' QUANDO FACCIO LOGOUT E MI RILOGGO CON UN'ALTRO UTENTE L'UTENTE TROVA LO STESSO POST QUANTI SONO GLI USERS REGISTRATI ...............

RISOLTO UNO INIZIA L'ALTRO ............

POSTO LO SCRIPT COMPLETO E IL VARDUMP CHE MI RESTITUISCE

PHP:
<?php


class Wall_Updates {

public $perpage = 100; // Uploads perpage
    

	
     // Updates   	
	  public function Updates($uid,$lastid) 
	{
	  // More Button
       $morequery="";
		if($lastid)
		$morequery=" and M.msg_id<'".$lastid."' ";
	   // More Button End
	   
	    $query = mysql_query("SELECT M.msg_id, M.uid_fk, M.message, M.created, U.username, M.uploads FROM messages M, users U WHERE M.uid_fk='$uid' AND M.uid_fk = U.uid OR M.uid_fk IN  ( SELECT user_1 FROM relationship AS R WHERE R.user_2 = '$uid' AND R.amico = 'S' ) OR M.uid_fk IN  ( SELECT user_2 FROM relationship AS R WHERE R.user_1 = '$uid' AND R.amico = 'S')  $morequery order by M.msg_id desc limit " .$this->perpage) or die(mysql_error());
	 var_dump($query);
         while($row=mysql_fetch_array($query))
		$data[]=$row;
		  var_dump($data);  
	    return $data;
	   
  	
    }
	   
	   
	   // Updates   	
	  public function Total_Updates($uid) 
	{
	 	   
	    	   $query = mysql_query("SELECT M.msg_id, M.uid_fk, M.message, M.created, U.username, M.uploads FROM messages M, users U WHERE M.uid_fk = U.uid AND M.uid_fk='$uid' AND M.uid_fk = U.uid OR M.uid_fk IN  ( SELECT user_1 FROM relationship AS R WHERE R.user_2 = '$uid' AND R.amico = 'S' ) OR M.uid_fk IN  ( SELECT user_2 FROM relationship AS R WHERE R.user_1 = '$uid' AND R.amico = 'S')  $morequery order by M.msg_id ") or die(mysql_error());
		 var_dump($query);
		$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.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 $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($uid) 
	{
	    $query = mysql_query("SELECT nome_file_vero FROM `users` WHERE uid='$uid'") or die(mysql_error());
	   $row=mysql_fetch_array($query);
	   if(!empty($row['nome_file_vero']))
	   {
	    $profile_pic_path=$base_url.'nome_file_vero/';
	    $data=    $profile_pic_path.$row['nome_file_vero'];
        return $data;
         }
		 else
		 {
		 $data="icons/default.jpg";
		return $data;
		 }
	}
	//  Gravatar 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,$uploads) 
	{
	$update=mysql_real_escape_string($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']) {
		  $uploads_array=explode(',',$uploads);
		  $uploads=implode(',',array_unique($uploads_array));
            $query = mysql_query("INSERT INTO `messages` (message, uid_fk, ip,created,uploads) VALUES (N'$update', '$uid', '$ip','$time','$uploads')") 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' and uid_fk='$uid' ") 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;
      	       
    }
	
		//Image Upload
		public function Image_Upload($uid, $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,uid_fk)values('$image' ,'$uid')") or die(mysql_error());
		$ids = mysql_insert_id();
        return $ids;
    }
	
			//get Image Upload
		public function Get_Upload_Image($uid,$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 uid_fk='$uid' 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($uid,$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 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 (N'$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;
      	       
    }

    

}

?>

VARDUMP

resource(9) of type (mysql result) array(100) { [0]=> array(12) { [0]=> string(3) "338" ["msg_id"]=> string(3) "338" [1]=> string(2) "55" ["uid_fk"]=> string(2) "55" [2]=> string(12) "fdsgdfgdsdfg" ["message"]=> string(12) "fdsgdfgdsdfg" [3]=> string(10) "1322938090" ["created"]=> string(10) "1322938090" [4]=> string(11) "stefaninius" ["username"]=> string(11) "stefaninius" [5]=> string(1) "0" ["uploads"]=> string(1) "0" } [1]=> array(12) { [0]=> string(3) "338" ["msg_id"]=> string(3) "338" [1]=> string(2) "55" ["uid_fk"]=> string(2) "55" [2]=> string(12) "fdsgdfgdsdfg" ["message"]=> string(12) "fdsgdfgdsdfg" [3]=> string(10) "1322938090" ["created"]=> string(10) "1322938090" [4]=> string(3) "300" ["username"]=> string(3) "300" [5]=> string(1) "0" ["uploads"]=> string(1) "0" } [2]=> array(12) { [0]=> string(3) "338" ["msg_id"]=> string(3) "338" [1]=> string(2) "55" ["uid_fk"]=> string(2) "55" [2]=> string(12) "fdsgdfgdsdfg" ["message"]=> string(12) "fdsgdfgdsdfg" [3]=> string(10) "1322938090" ["created"]=> string(10) "1322938090" [4]=> string(10) "miriamuzza" ["username"]=> string(10) "miriamuzza" [5]=> string(1) "0" ["uploads"]=> string(1) "0" } [3]=> array(12) { [0]=> string(3) "338" ["msg_id"]=> string(3) "338" [1]=> string(2) "55" ["uid_fk"]=> string(2) "55" [2]=> string(12) "fdsgdfgdsdfg" ["message"]=> string(12) "fdsgdfgdsdfg" [3]=> string(10) "1322938090" ["created"]=> string(10) "1322938090" [4]=> string(11) "miriam alba" ["username"]=> string(11) "miriam alba" [5]=> string(1) "0" ["uploads"]=> string(1) "0" } [4]=> array(12) { [0]=> string(3) "338" ["msg_id"]=> string(3) "338" [1]=> string(2) "55" ["uid_fk"]=> string(2) "55" [2]=> string(12) "fdsgdfgdsdfg" ["message"]=> string(12) "fdsgdfgdsdfg" [3]=> string(10) "1322938090" ["created"]=> string(10) "1322938090" [4]=> string(8) "paperino" ["username"]=> string(8) "paperino" [5]=> string(1) "0" ["uploads"]=> string(1) "0" } [5]=> array(12) { [0]=> string(3) "338" ["msg_id"]=> string(3) "338" [1]=> string(2) "55" ["uid_fk"]=> string(2) "55" [2]=> string(12) "fdsgdfgdsdfg" ["message"]=> string(12) "fdsgdfgdsdfg" [3]=> string(10) "1322938090" ["created"]=> string(10) "1322938090" [4]=> string(0) "" ["username"]=> string(0) "" [5]=> string(1) "0" ["uploads"]=> string(1) "0" } [6]=> array(12) { [0]=> string(3) "338" ["msg_id"]=> string(3) "338" [1]=> string(2) "55" ["uid_fk"]=> string(2) "55" [2]=> string(12) "fdsgdfgdsdfg" ["message"]=> string(12) "fdsgdfgdsdfg" [3]=> string(10) "1322938090" ["created"]=> string(10) "1322938090" [4]=> string(8) "stefanix" ["username"]=> string(8) "stefanix" [5]=> string(1) "0" ["uploads"]=> string(1) "0" } [7]=> array(12) { [0]=> string(3) "338" ["msg_id"]=> string(3) "338" [1]=> string(2) "55" ["uid_fk"]=> string(2) "55" [2]=> string(12) "fdsgdfgdsdfg" ["message"]=> string(12) "fdsgdfgdsdfg" [3]=> string(10) "1322938090" ["created"]=> string(10) "1322938090" [4]=> string(7) "stefano" ["username"]=> string(7) "stefano" [5]=> string(1) "0" ["uploads"]=> string(1) "0" } [8]=> array(12) { [0]=> string(3) "338" ["msg_id"]=> string(3) "338" [1]=> string(2) "55" ["uid_fk"]=> string(2) "55" [2]=> string(12) "fdsgdfgdsdfg" ["message"]=> string(12) "fdsgdfgdsdfg" [3]=> string(10) "1322938090" ["created"]=> string(10) "1322938090" [4]=> string(5) "admin" ["username"]=> string(5) "admin" [5]=> string(1) "0" ["uploads"]=> string(1) "0" } [9]=> array(12) { [0]=> string(3) "338" ["msg_id"]=> string(3) "338" [1]=> string(2) "55" ["uid_fk"]=> string(2) "55" [2]=> string(12) "fdsgdfgdsdfg" ["message"]=> string(12) "fdsgdfgdsdfg" [3]=> string(10) "1322938090" ["created"]=> string(10) "1322938090" [4]=> string(10) "MiriamAlba" ["username"]=> string(10) "MiriamAlba" [5]=> string(1) "0" ["uploads"]=> string(1) "0" } [10]=> array(12) { [0]=> string(3) "338" ["msg_id"]=> string(3) "338" [1]=> string(2) "55" ["uid_fk"]=> string(2) "55" [2]=> string(12) "fdsgdfgdsdfg" ["message"]=> string(12) "fdsgdfgdsdfg" [3]=> string(10) "1322938090" ["created"]=> string(10) "1322938090" [4]=> string(10) "stefanino3" ["username"]=> string(10) "stefanino3" [5]=> string(1) "0" ["uploads"]=> string(1) "0" } [11]=> array(12) { [0]=> string(3) "338" ["msg_id"]=> string(3) "338" [1]=> string(2) "55" ["uid_fk"]=> string(2) "55" [2]=> string(12) "fdsgdfgdsdfg" ["message"]=> string(12) "fdsgdfgdsdfg" [3]=> string(10) "1322938090" ["created"]=> string(10) "1322938090" [4]=> string(6) "minnye" ["username"]=> string(6) "minnye" [5]=> string(1) "0" ["uploads"]=> string(1) "0" } [12]=> array(12) { [0]=> string(3) "337" ["msg_id"]=> string(3) "337" [1]=> string(2) "55" ["uid_fk"]=> string(2) "55" [2]=> string(4) "fsdf" ["message"]=> string(4) "fsdf" [3]=> string(10) "1322938086" ["created"]=> string(10) "1322938086" [4]=> string(7) "stefano" ["username"]=> string(7) "stefano" [5]=> string(1) "0" ["uploads"]=> string(1) "0" }

ECC ECC TAGLIO IL POST PERCHè TROPPO LUNGO ( SOLO CHE è TROPPO STRANO UN VARDUMP COSI LUNGO PER 3 AMICI IN COMUNE E 20 POST IN TUTTO )
 
EVENTUALMENTE SE QUALCUNO TROVA UN MODO DIVERSO PER PIAZZARCI LA POSSIBILITà DI VEDERE I POST SOLO DEGLI AMICI POSTO LA TABELLA RELATIOSHIP ...

PHP:
CREATE TABLE IF NOT EXISTS `relationship` (  
`id` int(10) NOT NULL auto_increment,  
`user_1` varchar(10) NOT NULL,  
`user_2` varchar(10) NOT NULL,  
`amico` enum('S','N') NOT NULL default 'N',  
PRIMARY KEY (`id`)  
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=76 ;
 
Stato
Chiusa ad ulteriori risposte.

Discussioni simili