php - SQL is only getting 1 row -


i'm making system in php , have code usernames of people liked post using post id , if haven't liked post show button post , if haven't show button says unlike post , if there's no "no 1 has liked post first". when add in, 1 user id though multiple people have liked post, how fixed this, here code:

$fancy = $db->fetch("select * " . $prefix . "_fancy post_id = '" . $post_row['id'] . "' order id");  if ($fancy) {     $name = $user->name($fancy['account_id']);     if ($account['id'] !== $fancy['account_id']) {         $fancytext = '<div>'.$name.' post.<!-- begin logged_in --> <a href="./?area=forum&amp;s=topic&amp;t='.$topic_id.'&amp;f='.$pid.'"><img src="./template/default/images/like.png" alt="" border="0"/></a><!-- end logged_in --> </div>';     } else {         $fancytext = '<div>'.$name.' post.<!-- begin logged_in --> <a href="./?area=forum&amp;s=topic&amp;t='.$topic_id.'&amp;unf='.$pid.'"><img src="./template/default/images/unlike.png" alt="" border="0"/></a><!-- end logged_in --> </div>';     } } else {     $fancytext = '<div><i>no 1 has liked post, first!</i> <!-- begin logged_in --><a href="./?area=forum&amp;s=topic&amp;t='.$topic_id.'&amp;f='.$pid.'"><img src="./template/default/images/like.png" alt="" border="0"/></a><!-- end logged_in --> </div>'; } 

unleash power of pdo prepared statements , fetchall:

$sql = "select * $prefix_fancy post_id = :pid order id"; $stmt = $db->prepare($sql); $stmt->execute(array(':pid' => $post_row['id'])); $posts = $stmt->fetchall(pdo::fetch_assoc); 

now $posts holds selected records. use foreach iterate.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -