1

I have the following mysql query---

               $query="SELECT * FROM `wall_posts`
                       WHERE 
                       `login_name` = '" . $_SESSION['SESS_LOGIN'] . "'
                       OR
                       `login_name` IN (
                       SELECT friend_login
                       FROM friends
                       )
                       ORDER BY time DESC";

But when I execute it, it does'nt give me expected results also only one post is being displayed!

4
  • 1
    What is the expected result? Commented Mar 11, 2011 at 7:41
  • That all the post related to the login names in the friends table. Commented Mar 11, 2011 at 7:44
  • The cause of one post being returned is so broad. There may actually only be one post, could be the way you are reading the result, etc... Commented Mar 11, 2011 at 7:45
  • interpolating values (such as $_SESSION['SESS_LOGIN']) into queries is dangerous. It may be safe in this instance, but in others you could be opening your site to SQL injection, which is a very serious security risk. To prevent this, always use parameters in prepared statements for values. Note that only simple values can be parameterized. Table names, column names, compound values and the like still need to be (carefully) interpolated. Commented Mar 11, 2011 at 8:15

1 Answer 1

1

Have you tried running it directly from within a mysql console/phpmyadmin?
And what is in friends? Is it a relation table? In that case you should probably add a WHERE somewhere because now you are selecting everything.

This code should return more then just 1 row if there are more. Perhaps your problem is in the way you display the results. What is the result of:

$result = mysql_query($query);
echo 'Number of rows: ' . mysql_num_rows($result);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.