Jump to content

what is wrong with the query here?


shan2batman
Go to solution Solved by Barand,

Recommended Posts

hi, i'm trying to verify whether someone has like a post or not here and it is not giving the expected output but a empty array.Any help would be great. Thanks in advance.

    //fetch user_id from update table in db and inject it to the feed query.
    $totalUpdates=$project->totalUpdates1($id,$load);   
    $total_sess_count=$project->totalupdatescount($id);
   
    foreach ($totalUpdates as $j=>$row1) {
   
                $updateid=$row1['update_id'];
                
                $account_name=$row1['account_name'];
                $u_id=$row1['user_id_u'];
                $author=$row1['author'];
                $post_date=$row1['time'];
                $title= stripslashes($row1['title']);
                $data= stripslashes($row1['update_body']);
              $data1=  hashtags($data);
              //$data1=  taggingsys($data0);
              $pic=$project->viewByUname($author);
              $uid=$pic['user_id'];
         $datemade = strftime("%B %d", strtotime($post_date));
           $avatar=$pic['avatar'];
          if ($avatar!=""){
          $feed_pic='user/'.$uid.'/'.$avatar;
      }  else {
          $feed_pic='img/avatardefault.png';
          }
//logic to check if someone has liked or not.
          $liked_check="select voted_id from voted_u where user_id_v=:sess_id and vote_4_update_id=:updateid ";
          $stmt_liked=$conn->prepare($liked_check);
          $stmt_liked->bindValue(":sess_id", $_SESSION['id']);
         $stmt_liked->bindValue(":updateid",$updateid);
          $like_check=$stmt_liked->fetchAll();
          if ($like_check>0) {
              $uname_liked=TRUE;
          }
Link to comment
Share on other sites

Without knowing what is stored to define whether a like has been attached and what exactly you should be getting back we won't know if there is an issue with the query, syntactically the php looks ok but it's always a worthy debugging step to fling in a var_dump($stmt_liked->errorInfo()) just after the query to see if it's doing what it should be.

Link to comment
Share on other sites

this would be another good reason to ascend to a higher plane of programming existence and reuse proven, tested, general purpose code.  so that each time you do the same thing, you don't have to beat on the keyboard typing out bespoke code and queries, then find and fix all the typo's and missing or wrong statements. reusing proven, tested, and general purpose code will let you concentrate on the program flow and the goal you are actually trying to accomplish, rather than on the tedious details of each step you take along the way.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.