Jump to content

shan2batman

Members
  • Posts

    90
  • Joined

  • Last visited

Everything posted by shan2batman

  1. hi, guys im trying to echo out some values. but, am having a hard time to echo it out. when i try to print it with print_r its printing but not echoing.So, checked the source code and foundout that the document is not printing after the header. so, changed the file permissions to 777 (im using ubuntu).still it is not working, dont know what to do??? i have attached a screenshot of my source code in the browser below:- here is my code:- <?php include 'includes/header.php'; if(!isset($_SESSION['uname'])){ echo 'You must login to view this'; } $g=""; $gname=""; $gcreation=""; $glogo=""; $invrule=""; $privrule=""; $creator=""; $gmembers=""; $moderators=array(); $approved=array(); $pending=array(); $all=array(); $joinbtn=""; $addmembers=""; $addadmin=""; $profile_pic_btn=""; $avatar_form=""; $mainposts=""; if(isset($_GET['g'])){ $g=htmlentities($_GET['g']); print_r($g); } else { header("location: index.php?nogroup4u"); //exit(); } #make sure the group exists & get data. $query="select * from groups where name=:g limit 1"; $stmt=$conn->prepare($query); $stmt->bindValue(":g",$g); $stmt->execute(); $numrows=$stmt->rowCount(); $fetch1=$stmt->fetchAll(); if ($numrows<1) { echo 'That group doesnt exist'; //exit(); } else { foreach ($fetch1 as $row) { $g_id=$row['g_id']; $gname=$row['name']; $gcreation=$row['creation']; $glogo=$row['logo']; $invrule=$row['invrule']; $creator=$row['creator']; $profile_pic_btn.='<img src="group/'.$g_id.'/'.$glogo.'" alt="'.$gname.'">'; } } #set session for group. $_SESSION['group']=$gname; #get member data $sql1="select g.mname,g.approved,g.admin,u.avatar,u.user_id,u.uname from gmembers as g left join user as u on u.uname=g.mname where g.gname=:g"; $stmt1=$conn->prepare($sql1); $stmt1->bindValue(":g",$g); $stmt1->execute(); $row_fetch=$stmt1->fetchAll(); foreach ($row_fetch as $row1) { $mName=$row1['mname']; $app=$row1['approved']; $admin=$row1['admin']; $avatar=$row1['avatar']; $u_id=$row1['user_id']; #set user image if ($avatar!="") { $member_pic="user/".$u_id."/".$avatar; } else { $member_pic="img/avatardefault.png"; } #determine if approved switch($app){ case 0: array_push($pending, $mName); array_push($all, $mName); break; case 1: array_push($approved, $mName); array_push($all, $mName); break; } print_r($app); #determine if admin if($admin==1){ array_push($moderators, $mName); } $mod_count=count($moderators); $app_count= count($approved); $pend_count=count($pending); if ($app==1) { $gmembers.='<a href="home.php?u='.$mName.'?v="'.$_SESSION['uname'].'"><img src="'.$member_pic.'" width="70" height="70"></a>'; } } if(isset($_SESSION['uname'])&&(!in_array($_SESSION['uname'], $all))){ $joinbtn.= "<button id='joinBtn' action='joingroup'>Join group</button>"; } #pending members section for admin if(in_array($_SESSION['uname'], $moderators)){ $addmembers="<h3>Pending Members</h3>"; for ($x = 0; $x < $pend_count; $x++) { $addmembers="<a href='home.php?u={$pending[$x]}?v={$_SESSION["uname"]}'>{$pending[$x]}</a><br> <button id='appBtn' action='approve_member'>Approve</button> | " . "<button id='decBtn' action='decline_member'>Decline</button>"; } } if(in_array($_SESSION['uname'], $moderators)){ $addadmin="<h3>Add Admin</h3><input type='text' name='new_admin' id='new_admin'><button id='add_adm'>Add</button>"; } $sql="select g.*,u.avatar,u.user_id from group_posts as g left join user as u on username=g.author where g.gname=:g and type='0' order by pdate desc"; $stmt2=$conn->prepare($sql); $stmt2->bindValue(":g",$g); $stmt2->execute(); $num_rows=$stmt2->rowCount(); $fetch=$stmt2->fetchAll(); if ($num_rows>0) { foreach ($fetch as $v) { $postid=$v['id']; $post_auth=$v['author']; $post_type=$v['type']; $post_data=$v['data']; $post_date=$v['pdate']; $post_avatar=$v['avatar']; $post_uid=$v['user_id']; if ($post_avatar != ""){ $g_pic='user/'.$post_uid.'/'.$avatar; } else { $g_pic='img/avatardefault.png'; } $user_image="<img src='".$g_pic."' alt='{$post_auth}' title='{$post_auth}' width='50' height='50'>"; #build threads. $main_posts="<div id='PB_".$postid."' class='jumbotron'>" . "<legend>Posted by:{$g_pic}' '{$post_auth}-- {$post_date}</legend><br>" . "{$post_data}<br><hr><br>"; #get replies and user image using inner loop $sql2="select g.author,g.data,g.pdate,u.avatar,u.user_id from group_posts as g left join users as u on u.uname=g.author where pid=:post_id"; $stmt3=$conn->prepare($sql2); $stmt3->bindValue(":post_id",$postid); $stmt3->execute(); $num_rows1=$stmt3->rowCount(); $fetch1=$stmt3->fetchAll(); if ($num_rows1>0) { foreach ($fetch as $row1) { $reply_auth=$row1['author']; $reply_data=$row1['data']; $reply_date=$row1['date']; $reply_avatar=$row1['avatar']; $reply_uid=$row1['user_id']; if ($reply_avatar != ""){ $r_pic='user/'.$reply_uid.'/'.$avatar; } else { $r_pic='img/avatardefault.png'; } $reply_img="<img src='".$r_pic."' alt='{$reply_auth}' title='{$reply_auth}' width='50' height='50'>"; #build replies $main_posts="<div id='reply_body' class='jumbotron'>" . "<legend>Posted by:{$g_pic}' '{$reply_auth}-- {$reply_date}</legend><br>" . "{$reply_data}</div><br><hr><br>"; } $main_posts='<br>' . '<textarea id="reply_textarea_'.$postid.'" class="group_reply_ input-custom2" placeholder="comment\'s"></textarea>' . '<button id="'.$postid.'" attr="'.$postid.'" type="b" class="btn btn-warning pull-right btn-sm reply_butn reply">Reply</button></div>'; } } } ?> <div class="container-fluid"> <br><div class="row"> </div><br> <div class="row"> <div class="col-sm-2"> </div> <div class="col-lg-8"> <?php echo $gmembers."".$addadmin."".$addmembers;?> </div> <div class="col-sm-2"> </div> </div> </div> <script type="text/javascript"> $(".fancybox-effects").fancybox(); $("button.delete_photo").click(function(){ var del_id = $(this).attr('id'); var del_attr=$(this).attr('attr'); $.post("others/delete_photo.php", {id:del_id},function(data){ $("."+del_id).slideUp('slow', function() {$(this).remove();}); } ); }); $(".upload_button").click(function() { }); </script> </body> </html> any help would be appreciated
  2. I'm trying to create a basic websocket chat from a tutorial in YouTube and I'am facing this error in the terminal when i run > php bin/server.php My code is as follows for chat.php:- <?php namespace MyApp; use Ratchet\MessageComponentInterface; use Ratchet\ConnectionInterface; class chat implements MessageComponentInterface { protected $clients; public function __construct() { $this->clients=new \SplObjectStorage; } public function onOpen(ConnectionInterface $conn) { $this->clients->attach($conn); } public function onClose(ConnectionInterface $conn) { $this->clients->detach($conn); } public function onMessage(ConnectionInterface $conn,$msg) { foreach($this->clients as $client){ if($client !==$conn){ $client->send($msg); } } } public function onError(ConnectionInterface $conn, \Exception $e) { echo "the following error occured: ".$e->getMessage(); $conn->close(); } } code for server.php:- <?php require 'chat.php'; require __DIR__ .'/vendor/autoload.php'; use Ratchet\Server\IoServer; use Ratchet\Http\HttpServer; use Ratchet\WebSocket\WsServer; $server=IoServer::factory(new HttpServer(new WsServer (new chat())) , 8080); $server->run(); Any help would be appreciated.
  3. Guys im trying to join a comments table to posts table using the following query in a method. public function feedView($session,$friend,$updateid) { $sql2=" select u.update_body,u.author,u.time,u.title,u.account_name,u.update_id," . "c.comment_body, c.os_id,c.author_c,c.time_c,c.comment_id,c.type_c " . "from updates u join comment_update c " . "on c.os_id=:statusid WHERE u.account_name = :session or u.account_name=:friend and (u.type = 'a' or 'c') order by u.time asc,c.time_c desc"; $stmth= $this->_db->prepare($sql2); $stmth->bindValue(":session",$_SESSION['uname']); $stmth->bindValue(":friend",$friend); $stmth->bindValue(":statusid",$updateid); $stmth->execute(); return $stmth->fetchAll(PDO::FETCH_ASSOC); } it prints the posts fine but the problem is with comments content where it seems to print the comments in the same posts twice. don't know where the bug is coming from. here is how it is displaying feeds:-
  4. so you are suggesting to redesign the way it works completely @jacques1 (sorry my code is messy im still learning), ill do what u suggested. and will come here if i couldn't find any resources online. thanks anyway bro.
  5. i'm attaching a screenshot of how the DB looks like.
  6. update: i did do a "union all" query in a separate page to get the comments attached to the posts but alas the comments just appear for all posts where it shouldn't to. can anyone shed any lights on this ??? the database structure is like this : the user posts an article which is of type"a" or "c", and the other users can reply to the post which is of type "b". which is inserted in a single table called updates. The os_id is created using the "last insert id" through php and update_id is auto increment the rest are session variables for account_name &author and user input for update_body and title.
  7. thanks, gizmola, actually the first query is to actually fetch the posts and the second query is to actually fetch comments since im not that good in mysql i dont know how to join them both in my code. any help would be appreciated. once again thanks. actually there is no id involved in procuring the posts that is just the author name.
  8. Guys I'm trying to actually create a commenting system in my example site(for educational purposes). But the problem that I face now is that it is not working as it is supposed to as, the comments for the post with id 116is displaying for all the posts. But should only show for status with the id 116. i created the post system to have only the type “**a**”or “**c**” and the comments to be “b” to be inserted in to mysql. But the comments are showing up for all Posts, no matter where I comment it shows up for all posts. Any help would be appreciated. Here is the code that has the post logic: <?php include '../includes/dbconfig.inc.php'; $status2view=$project->statusView($f_uname); foreach($status2view as $row){ //print_r($row); $updateid=$row['update_id']; //gives output on var_dump $status_reply_=$project->reply2StatusView($updateid); foreach ($status_reply_ as $row) { $status_reply_id=$row['update_id']; $reply_author=$row['author']; $reply_d=htmlentities($row['update_body']); $reply_data= stripslashes($reply_d); $reply_osid=$row['os_id']; $account_name=$row['account_name']; $reply_date=$row['time']; $reply_delete_button=""; if ($reply_author==$session_uname || $account_name==$session_uname) { $reply_delete_button="<li><span id='$status_reply_id' class='delete_reply_btn glyphicon glyphicon-remove'><a href='#' title='Delete this comment'>Remove X</a></span></li>"; } if ($reply_osid!=$updateid) { $status_replies.=""; } else { $status_replies.="<div class='replyboxes pull-left reply_".$status_reply_id."'><b>Reply by:-<a href='search_results.php?u=".$reply_author."'>".$reply_author."</a>" . "<span class='pull-right'>".$reply_date . "<b class='caret'> <small><span class='btn-xs btn-danger dropdown-toggle pull-right' data-toggle='dropdown' aria-expanded='true' ><span class='glyphicon glyphicon-edit'></span> <ul class='dropdown-menu'>".$reply_delete_button . "<li><a href='#' class='hidden_text_area glyphicon glyphicon-pencil reply_".$status_reply_id."' title='Edit this comment' >Edit</a></li>" . "<li><a href='report.php?u='".$reply_author."'>Report</a><li></ul>" . "</span></span></small></b><br><legend>". html_entity_decode($reply_data)."</legend><br></div>"; } } } foreach ($status2view as $row1) { //got values here. $updateid=$row1['update_id']; $account_name=$row1['account_name']; $os_id=$row1['os_id']; $author=$row1['author']; $post_date=$row1['time']; $title= stripslashes($row1['title']); $data= stripslashes($row1['update_body']); $statusdeletebutton=''; //insert_status_ui script to get message. if($isowner=="yes"){ $statusui_edit="<div type='".$updateid."' class='hidden_edit_4_session session_editor".$updateid." jumbotron'>" . "<a href='#' type='".$updateid."' class='pull-right close_edit' title='Close without editing'>Close X</a>" . "<input type='text' class='form-control title_s_edit title_s_".$updateid."' name='status_title' value='".html_entity_decode($title)."' placeholder='Title' >" . "<span> </span>" . "<textarea id='wall_edit_1' type='".$updateid."' rows='5' cols='50' class='session_edit text_value_".$updateid."' wrap='hard' placeholder='whats up ".$session_uname."'> ".html_entity_decode($data)."</textarea><br>" . "<button style='float:right;' value='".$updateid."' type='a' class='btn btn-warning btn btn-large btn-lg post-s-edit'>Update</button></div>" ; } elseif ($is_friend==TRUE&&$session_uname!=$f_uname) { $statusui_edit="<div type='".$updateid."' class='hidden_edit_4_friend friend_editor".$updateid." jumbotron'>" . "<a title='Close without editing' type='".$updateid."' href='#' class='pull-right close_edit_f'>Close X</a>" . "<input type='text' class='form-control title_f_edit title_f_".$updateid."'' name='status_title' value='".html_entity_decode($title)."' placeholder='Title'><br>" . "<div> </div>" . "<textarea id='wall_edit_2' value='' type='".$updateid."' rows='5' cols='50' class='friend_edit update_friend_".$updateid."' placeholder='hi ".$session_uname." want to say something to ".$f_uname.". '>" .html_entity_decode($data)."</textarea><br>" . "<button style='float:right;' value='".$updateid."' type='c' class='btn btn-warning btn-large btn-lg post-f-edit'>Update</button></form></div>"; } if ($author==$session_uname || $account_name==$session_uname) { $statusdeletebutton='<li>' . '<a href="#" type="'.$updateid.'" class="delete_4_session hidden_text_delete_'.$updateid.' glyphicon glyphicon-trash delete_reply_btn" title="Delete this status and its replies">Remove</a></li>'; } if($isowner=="yes"){ $status_list= $statusui_edit.'<div attr="'.$updateid.'" type="'.$updateid.'" class="statusboxes status_'.$updateid.' jumbotron">' . '<h3 style="color:black; margin-bottom:5px; margin-top:5px;" class="pull-left">' . '<div id="'.$updateid.'" class="title_s_2copy" value="'.html_entity_decode($title).'">'.html_entity_decode($title).'</div></h3>' . '<span class="pull-right">' . '<div class="dropdown">' . '<button type="button" class="btn btn-danger dropdown-toggle" data-toggle="dropdown" >' . '<span class="glyphicon glyphicon-edit"></span></button>' . '<ul class="dropdown-menu">' . '<li><a href="#" attr="'.$updateid.'" type="'.$updateid.'" class="edit_4_session hidden_text_edit glyphicon glyphicon-pencil" title="Edit this status" >Edit</a></li>'.$statusdeletebutton.'</ul></div></span><br><hr>' . '<legend><span class=" data_s_2copy" type="'.$updateid.'" value="'.html_entity_decode($data).'">' . html_entity_decode($data).'</span><br><br></legend><b style="text-align:right; color:black;"><small>Posted by:- <a href="search_results.php?u='.$author.'">'.$author. '</a> '.$post_date.'</small></b>' . '<br><p>'.$status_replies.'</p><br>'; if ($is_friend==TRUE||$session_uname==$f_uname) { $status_list.= '<textarea id="'.$updateid.'" class="status_reply_'.$updateid.' input-custom2" placeholder="comment\'s"></textarea>' . '<button id="reply_btn_'.$updateid.'" attr="'.$updateid.'" type="b" class="btn btn-warning pull-right btn-sm reply_btn reply_'.$updateid.'">Reply</button></div>'; } }elseif ($is_friend==TRUE&&$session_uname!=$f_uname) { $status_list= $statusui_edit.'<div attr="'.$updateid.'" type="'.$updateid.'" class="statusboxes status_'.$updateid.' jumbotron">' . '<h3 style="color:black; margin-bottom:5px; margin-top:5px;" class="pull-left">' . '<div id="'.$updateid.'" class="title_s_2copy" value="'.html_entity_decode($title).'">'.html_entity_decode($title).'</div></h3><br><hr>' . '<legend><span class=" data_s_2copy" type="'.$updateid.'" value="'.html_entity_decode($data).'">' . html_entity_decode($data).'</span><br><br></legend><b style="text-align:right; color:black;"><small>Posted by:- <a href="search_results.php?u='.$author.'">'.$author. '</a> '.$post_date.'</small></b>' . '<br><p>'.$status_replies.'</p><br>'; $status_list.= '<textarea id="'.$updateid.'" class="status_update input-custom2" placeholder="comment\'s"></textarea>' . '<button id="reply_btn'.$updateid.'" attr="'.$updateid.'" type="b" class="btn btn-warning pull-right btn-sm reply_btn reply_'.$updateid.'">Reply</button></div>'; } echo $status_list; } here is the class method: public function statusView($f_uname) { $sql="select * from updates where account_name=:either and type='a' or account_name=:either and type='c' order by time desc limit 20"; $stmth=$this->_db->prepare($sql); $stmth->bindValue(":either",$f_uname); $stmth->execute(); return $stmth->fetchAll(PDO::FETCH_ASSOC); } public function reply2StatusView($updateid){ try{ $stmth= $this->_db->prepare("select * from updates where os_id=:statusid and type='b' order by time asc"); $stmth->bindparam(":statusid", $updateid); $stmth->execute(); return $stmth->fetchAll(PDO::FETCH_ASSOC); } catch (Exception $exc){ echo $exc->getMessage(); } }
×
×
  • 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.