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.

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?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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