Ti dovrebbero dare un premio su questo forum x la tua gentilezza ...
Ehm, sì... prima o poi. :evil:poi con borgo sicuro ne esci
class Wall_Updates {
// Updates
public function Updates($uid)
{
$q=mysql_query("SELECT user_1, user_2 FROM relationship WHERE (user_1=$uid OR user_2=$uid) AND amico='S'");
while($am=mysql_fetch_assoc($q)){
$amici_grezzi[]=$am['user_1'];
$amici_grezzi[]=$am['user_2'];
}
//ripulisci l'array dei valori duplicati
foreach($amici AS $valore){
$q=mysql_query("SELECT M.msg_id, M.uid_fk, M.message, M.created, U.username FROM messages AS M, users AS U WHERE M.uid_fk=$valore");
$row=mysql_fetch_array($q);
$data[0]=$row['msg_id'];//da php 5 il primo elemento di push deve essere un array
array_push($data,$row['uid_fk'],$row['uid_fk'],$row['message'],$row['created'],$row['username']);
}
var_dump($data);
//return $data;
return $data;
}
class Wall_Updates {
// Updates
public function Updates($uid)
{
$q=mysql_query("SELECT user_1, user_2 FROM relationship WHERE (user_1=$uid OR user_2=$uid) AND amico='S'");
while($am=mysql_fetch_assoc($q)){
$amici_grezzi[]=$am['user_1'];
$amici_grezzi[]=$am['user_2'];
}
//ripulisci l'array dei valori duplicati
$amici=array_unique($amici_grezzi);
foreach($amici AS $valore){
$q=mysql_query("SELECT M.msg_id, M.uid_fk, M.message, M.created, U.username FROM messages AS M, users AS U WHERE M.uid_fk=$valore");
$row=mysql_fetch_array($q);
$data[0]=$row['msg_id'];//da php 5 il primo elemento di push deve essere un array
array_push($data,$row['uid_fk'],$row['message'],$row['created'],$row['username']);
}
//return $data;
return $data;
}
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, relationship AS r WHERE M.uid_fk=U.uid and M.uid_fk='$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());
while($row=mysql_fetch_array($query))
$data[]=$row;
return $data;
}
<?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, relationship AS r WHERE M.uid_fk=U.uid and M.uid_fk='$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());
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' $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.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 profile_pic FROM `users` WHERE uid='$uid'") 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($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;
}
}
?>
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=U.uid and M.uid_fk='$uid' $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
<?php
//...
$q=mysql_query("SELECT user_1, user_2 FROM relationship WHERE (user_1=$uid OR user_2=$uid) AND amico='S'");
while($am=mysql_fetch_assoc($q)){
$amici_grezzi[]=$am['user_1'];
$amici_grezzi[]=$am['user_2'];
}
//ripulisci l'array dei valori duplicati
$amici=array_unique($amici_grezzi);
foreach($amici AS $valore){
$q=mysql_query("SELECT M.msg_id, M.uid_fk, M.message, M.created, U.username FROM messages AS M, users AS U WHERE M.uid_fk=$valore");
$row=mysql_fetch_array($q);//qui se vuoi puoi sostituire con mysql_fetch_assoc
$data[]=$row['msg_id'];//errore AVEVO MESSO $data[0]
array_push($data,$row['uid_fk'],$row['message'],$row['created'],$row['username']);
}
var_dump($data);
//.....
?>
<?php
$numero=count($data);
for($k=0;$k < $numero; $h+=5){//cioè increnmentare di 5 in 5 dato che i valori congrui sono 5
echo "id messaggio ".$data[$k]."<br>";//per $k==0 -> $data[0] ; per $k==5 -> $data[5]
echo "id utente ".$data[$k+1]."<br>";//per $k==0 -> $data[1] ; per $k==5 -> $data[6]
echo "messaggio ".$data[$k+2]."<br>";//per $k==0 -> $data[2] ; per $k==5 -> $data[7]
echo "creato il ".$data[$k+3]."<br>";//per $k==0 -> $data[3] ; per $k==5 -> $data[8]
echo "username ".$data[$k+4]."<br><br>";//per $k==0 -> $data[4] ; per $k==5 -> $data[9] ecc....
}
?>
class Wall_Updates {
// Updates
public function Updates($uid)
{
$q=mysql_query("SELECT user_1, user_2 FROM relationship WHERE (user_1=$uid OR user_2=$uid) AND amico='S'");
while($am=mysql_fetch_assoc($q)){
$amici_grezzi[]=$am['user_1'];
$amici_grezzi[]=$am['user_2'];
}
//ripulisci l'array dei valori duplicati
$amici=array_unique($amici_grezzi);
foreach($amici AS $valore){
$q=mysql_query("SELECT M.msg_id, M.uid_fk, M.message, M.created, U.username FROM messages AS M, users AS U WHERE M.uid_fk=$valore");
$row=mysql_fetch_array($q);//qui se vuoi puoi sostituire con mysql_fetch_assoc
$data[]=$row['msg_id'];//errore AVEVO MESSO $data[0]
array_push($data,$row['uid_fk'],$row['message'],$row['created'],$row['username']);
}
var_dump($data);
//return $data;
return $data;
}
$Wall = new Wall_Updates();
if(isSet($_POST['update']))
{
$update=$_POST['update'];
$data=$Wall->Insert_Update($uid,$update);
if($data)
{
$msg_id=$data['msg_id'];
$message=tolink(htmlentities($data['message']));
$time=$data['created'];
$uid=$data['uid_fk'];
$username=$data['username'];
$face=$Wall->Gravatar($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')
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
// qui e sotto, l'altra volta c'era riuscito Alex, non so se ti ricordi ma la tabella relationship era riuscito lui a risolverla .. cmq secondo me dobbiamo se puoi aiutarmi se posso aiutarmi chi ne ha le capacità ad inserirlo direttamente qui .... perché infatti se uno non ha amici i post anche con la tabella modificata relationship funzionano correttamente e non si duplicano, si duplica tutto quando inserisco relatiosnhip quindi si vede che la query non è corretta per questo script
$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' $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($uid)
{
// qui e sotto, l'altra volta c'era riuscito Alex, non so se ti ricordi ma la tabella relationship era riuscito lui a risolverla .. cmq secondo me dobbiamo se puoi aiutarmi se posso aiutarmi chi ne ha le capacità ad inserirlo direttamente qui .... perché infatti se uno non ha amici i post anche con la tabella modificata relationship funzionano correttamente e non si duplicano, si duplica tutto quando inserisco relatiosnhip quindi si vede che la query non è corretta per questo script
$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' $morequery order by M.msg_id ") or die(mysql_error());
$data=mysql_num_rows($query);
return $data;
}
$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' OR M.uid_fk IN r.user_1 = '$uid' AND r.amico = 'S' $morequery order by M.msg_id desc limit " .$this->perpage) or die(mysql_error());