Jump to content

DB query not working


shan2batman

Recommended Posts

hi,

i'm trying to fetch results for one of my projects but it isn't fetching results can anyone help pl.

here is the code:

 

if($friend_username !=$_SESSION['uname']){         
  $mark1="select os_id,parent,r_seen,rread,sread,receiver,sender from private_message where (receiver=:sess or sender=:sess) and has_replies='1' and rread='1' and sread='0'";
$stmt_m1=$conn->prepare($mark1);
$stmt_m1->bindValue(":sess", $_SESSION['uname']);
//$stmt_m->bindValue(":f_uname", $f_uname);
$stmt_m1->execute();
$column1=$stmt_m1->fetchAll();
//this db query retrieves the pm_id
                var_dump($column1);
                $pmid=$column1['os_id'];
if ($column1['r_seen']=='0'&&$column1['parent']==$_SESSION['uname']) {
   
   print_r($column1);
      echo '<a href="private_message.php?u='.$friend_username.'&r_seen=1&pmid='.$pmid.'">'
          . '<img class="friendpics" src="'.$friend_pic.'" height="20" width="20" alt="'.$friend_username.'" title="'.$friend_username.'">'.$fname.' '.$lname.'<br>('
          .$friend_username.')</a><br><hr>';
    } elseif ($column1['r_seen']=='1'&&$column1['parent']==$_SESSION['uname']) {
         echo '<span class="label label-pill label-success" style="color: white; float:left;">New</span><div style="background: #cce0cc; height:125px; width:100%;"><a style="text-align:center;" href="private_message.php?u='.$friend_username.'&r_seen=1&pmid='.$pmid.'">'
          . '<img class="friendpics" src="'.$friend_pic.'" height="20" width="20" alt="'.$friend_username.'" title="'.$friend_username.'">'.$fname.' '.$lname.'<br>('
          .$friend_username.')</a></div><br><hr>';

      
    echo 'old';
    }elseif ($column1['r_seen']=='0'&&$column1['parent']!=$_SESSION['uname']) {
         echo '<span class="label label-pill label-success" style="color: white; float:left;">New</span><div style="background: #cce0cc; height:125px; width:100%;"><a style="text-align:center;" href="private_message.php?u='.$friend_username.'&r_seen=1&pmid='.$pmid.'">'
          . '<img class="friendpics" src="'.$friend_pic.'" height="20" width="20" alt="'.$friend_username.'" title="'.$friend_username.'">'.$fname.' '.$lname.'<br>('
          .$friend_username.')</a></div><br><hr>';

     
    echo'new';    
    
    }elseif ($column1['r_seen']=='1'&&$column1['parent']!=$_SESSION['uname']) 
        { 
         echo '<a href="private_message.php?u='.$friend_username.'&r_seen=1&pmid='.$pmid.'">'
          . '<img class="friendpics" src="'.$friend_pic.'" height="20" width="20" alt="'.$friend_username.'" title="'.$friend_username.'">'.$fname.' '.$lname.'<br>('
          .$friend_username.')</a><br><hr>';
            echo'new11';
    }
 else {
      
       print_r($f_uname);
      echo '<a href="private_message.php?u='.$friend_username.'&r_seen=1&pmid='.$pmid.'">'
          . '<img class="friendpics" src="'.$friend_pic.'" height="20" width="20" alt="'.$friend_username.'" title="'.$friend_username.'">'.$fname.' '.$lname.'<br>('
          .$friend_username.')</a><br><hr>';
    } 
 
    
    }
    
    }
 }
 echo '</div></div>';
 
      }

 

Link to comment
Share on other sites

For starters you have several mismatched curly braces. If you used a proper IDE you would spot basic errors like this right away. I would also suggest you learn one of the standard code formatting styles and stick to it. You also have a substantial amount of duplicate code. DRY - Don't Repeat Yourself.

Edited by benanamen
Link to comment
Share on other sites

18 minutes ago, shan2batman said:

@requinix the query is copied from another place where it is run plus i would like to know how to run queries manually.

You've never used MySQL from the command line? How about phpMyAdmin?

How are you writing these queries if you don't have a way to test that they work?

  • Like 1
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.