PHP PDO sql query and results -


i'm having issues implementing sql query using pdo.

$friend_emails = $pdo->prepare("select distinct user2                     members                     user1 = '$user'                     union                     select distinct user1                     members                     user2 = '$user'"); $friend_emails->execute();  for($i=0; $row = $friend_emails->fetch(); $i++) {      echo "foo"; } 

"foo" doesn't show @ all. var_dumped $row , $friend_emails->fetch() both of

boolean false 

so i'm not sure why is, thought return array of data.

any appreciated!

use while here

while($row = $friend_emails->fetch()) {     echo "foo"; } 

your loop never execute because

for($i=0; $row = $friend_emails->fetch(); $i++)           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ // here $i not present 

the correct format be

for($i=0; $i <= count($friend_emails->fetch()); $i++) 

Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -