Problemi estrazione username | PHP

Topic: Pubblico - Composto da 1 Post di 1 Utente.

24 Novembre, 2011 19:25 #1
searedone
Utente

searedone
Registrato: Mar, 2011
Posts: 10
Offline

buonasera a tutti, spero che tra di voi qualcuno possa darmi una mano
perché non so più dove sbattere la testa ;(

Ho una classe che vi posto due script mi dovrebbero restituire il messaggio con la foto e ok, ma non mi restituisce l'username ma l'id e l'username non mi viene fuori...

Spero davvero che qualcuno mi illumini o mi dica cosa sbaglio .

Classe functions

  1<?php
  2//Srinivas Tamada http://9lessons.info
  3//Wall_Updates
  4
  5class Wall_Updates {
  6
  7
  8    
  9     // Updates           
 10          public function Updates($uid) 
 11        {
 12        
 13        
 14                 $query = mysql_query("SELECT M.msg_id, M.uid_fk, M.message, M.created FROM messages M  WHERE M.uid_fk='$uid' OR M.uid_fk IN  (SELECT u.username FROM users AS u WHERE u.uid = u.uid AND u.uid = u.username )  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') order by M.msg_id desc  ") or die(mysql_error());     
 15                 while($row=mysql_fetch_array($query))
 16                $data[]=$row;
 17            return $data;
 18                
 19    }
 20        //Comments
 21           public function Comments($msg_id) 
 22        {
 23            $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());
 24           while($row=mysql_fetch_array($query))
 25            $data[]=$row;
 26        if(!empty($data))
 27                {
 28       return $data;
 29         }
 30        }
 31        
 32        //Avatar Image
 33        public function Gravatar($uid) 
 34        {
 35            $query = mysql_query("SELECT nome_file_vero FROM `users` WHERE uid='$uid'") or die(mysql_error());
 36           $row=mysql_fetch_array($query);
 37           if(!empty($row))
 38           {
 39            $email=$row['email'];
 40            $nome_file_vero=$row['nome_file_vero'];
 41        $lowercase = strtolower(nome_file_vero);
 42        $nome_file_vero = md5( $lowercase );
 43                $data="http://www.gravatar.com/avatar.php?gravatar_id=$imagecode";
 44                return $data;
 45         }
 46                 else
 47                 {
 48                 $data="default.jpg";
 49                return $data;
 50                 }
 51        }
 52        
 53        //Insert Update
 54        public function Insert_Update($uid, $update) 
 55        {
 56        $update=htmlentities($update);
 57           $time=time();
 58           $ip=$_SERVER['REMOTE_ADDR'];
 59        $query = mysql_query("SELECT msg_id,message FROM `messages` WHERE uid_fk='$uid' order by msg_id desc limit 1") or die(mysql_error());
 60        $result = mysql_fetch_array($query);
 61                
 62        if ($update!=$result['message']) {
 63            $query = mysql_query("INSERT INTO `messages` (message, uid_fk, ip,created) VALUES ('$update', '$uid', '$ip','$time')") or die(mysql_error());
 64            $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 ");
 65            $result = mysql_fetch_array($newquery);
 66                         return $result;
 67        } 
 68                else
 69                {
 70                                 return false;
 71                }
 72                
 73       
 74    }
 75        
 76        //Delete update
 77                public function Delete_Update($uid, $msg_id) 
 78        {
 79            $query = mysql_query("DELETE FROM `comments` WHERE msg_id_fk = '$msg_id' ") or die(mysql_error());
 80        $query = mysql_query("DELETE FROM `messages` WHERE msg_id = '$msg_id' and uid_fk='$uid'") or die(mysql_error());
 81        return true;
 82                     
 83    }
 84        
 85        //Insert Comments
 86        public function Insert_Comment($uid,$msg_id,$comment) 
 87        {
 88        $comment=htmlentities($comment);
 89                       $time=time();
 90           $ip=$_SERVER['REMOTE_ADDR'];
 91        $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());
 92        $result = mysql_fetch_array($query);
 93    
 94                if ($comment!=$result['comment']) {
 95            $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());
 96            $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 ");
 97            $result = mysql_fetch_array($newquery);
 98         
 99                   return $result;
100        } 
101                else
102                {
103                return false;
104                }
105       
106    }
107        
108        //Delete Comments
109                public function Delete_Comment($uid, $com_id) 
110        {
111            $query = mysql_query("DELETE FROM `comments` WHERE uid_fk='$uid' and com_id='$com_id'") or die(mysql_error());
112        return true;
113                     
114    }
115
116    
117
118}
119
120?>

La query incriminata

 1// Updates           
 2          public function Updates($uid) 
 3        {
 4        
 5        
 6                 $query = mysql_query("SELECT M.msg_id, M.uid_fk, M.message, M.created FROM messages M  WHERE M.uid_fk='$uid' OR M.uid_fk IN  (SELECT u.username FROM users AS u WHERE u.uid = u.uid AND u.uid = u.username )  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') order by M.msg_id desc  ") or die(mysql_error());     
 7                 while($row=mysql_fetch_array($query))
 8                $data[]=$row;
 9            return $data;
10                
11    }

dove la recupero ..

Messages

 1<?php
 2
 3error_reporting(0);
 4include_once 'includes/db.php';
 5
 6include_once 'includes/functions2.php';
 7
 8
 9include_once 'includes/tolink.php';
10include_once 'includes/time_stamp.php';
11include_once 'session.php';
12$Wall = new Wall_Updates();
13if(isSet($_POST['update']))
14{
15$update=$_POST['update'];
16$data=$Wall->Insert_Update($uid,$update);
17
18if($data)
19{
20
21$uid_fk=$_GET['uid'];
22$uid_fk=$_GET['username'];
23$msg_id=$data['msg_id'];
24$message=tolink(htmlentities($data['message']));
25$time=$data['created'];
26$username=$data['uid_fk'];
27$username=$data['username'];
28
29
30$nome_file_vero=$data['nome_file_vero'];
31$face=$Wall->Gravatar($uid);
32//$commentsarray=$Wall->Comments($msg_id);
33?>
34
35<div class="stbody" id="stbody<?php echo $msg_id;?>">
36<div class="stimg">
37<img src="<?php echo $face;?>" class='big_face'/>
38
39</div> 
40<div class="sttext">
41<a class="stdelete" href="#" id="<?php echo $msg_id;?>" title='Delete update'>X</a>
42<b><?php echo $username ;?></b> <?php echo $message;?>
43
44
45<div class="sttime"><?php time_stamp($time);?> | <a href='#' class='commentopen' id='<?php echo $msg_id;?>' title='Comment'>Comment </a></div> 
46<div id="stexpandbox">
47<div id="stexpand"></div>
48</div>
49<div class="commentcontainer" id="commentload<?php echo $msg_id;?>">
50<?php// include('load_comments.php') ?>
51</div>
52<div class="commentupdate" style='display:none' id='commentbox<?php echo $msg_id;?>'>
53<div class="stcommentimg">
54<img src="<?php echo $face;?>" class='small_face'/>
55</div> 
56<div class="stcommenttext" >
57<form method="post" action="">
58<textarea name="comment" class="comment" maxlength="200"  id="ctextarea<?php echo $msg_id;?>"></textarea>
59<br />
60<input type="submit"  value=" Comment "  id="<?php echo $msg_id;?>" class="comment_button"/>
61</form>
62</div>
63</div>
64</div> 
65</div>
66<?php
67}
68}
69?>

load_messages

 1<?php
 2
 3foreach($updatesarray as $data)
 4 {
 5 $msg_id=$data['msg_id'];
 6 $orimessage=$data['message'];
 7 $message=tolink(htmlentities($data['message']));
 8  $time=$data['created'];
 9   $username=$data['username'];
10 $uid=$data['uid_fk'];
11 $username=$data['uid_fk'];
12 $face=$Wall->Gravatar($uid);
13 $commentsarray=$Wall->Comments($msg_id);
14?>
15
16<script type="text/javascript"> 
17$(document).ready(function(){$("#stexpand<?php echo $msg_id;?>").oembed("<?php echo  $orimessage; ?>",{maxWidth: 400, maxHeight: 300});});
18</script>
19<div class="stbody" id="stbody<?php echo $msg_id;?>">
20
21<div class="stimg">
22<img src="<?php echo $face;?>" class='big_face'/>
23</div> 
24<div class="sttext">
25<a class="stdelete" href="#" id="<?php echo $msg_id;?>" title="Delete update">X</a>
26<b><?php echo $username;?></b> <?php echo $message;?>
27<div class="sttime"><?php time_stamp($time);?> | <a href='#' class='commentopen' id='<?php echo $msg_id;?>' title='Comment'>Comment </a></div> 
28
29<div id="stexpandbox">
30<div id="stexpand<?php echo $msg_id;?>"></div>
31</div>
32
33<div class="commentcontainer" id="commentload<?php echo $msg_id;?>">
34
35
36<?php include('load_comments.php') ?>
37
38
39
40
41
42</div>
43<div class="commentupdate" style='display:none' id='commentbox<?php echo $msg_id;?>'>
44<div class="stcommentimg">
45<img src="<?php echo $face;?>" class='small_face'/>
46</div> 
47<div class="stcommenttext" >
48<form method="post" action="">
49
50<textarea name="comment" class="comment" maxlength="200"  id="ctextarea<?php echo $msg_id;?>"></textarea>
51<br />
52<input type="submit"  value=" Comment "  id="<?php echo $msg_id;?>" class="comment_button"/>
53</form>
54
55
56</div>
57</div>
58
59
60</div> 
61
62</div>
63
64
65<?php
66
67  }
68?>

Condividi su:

Loggati o Registrati per replicare