2

I need to limit the first six results from a query with a condition WHERE.

I would like to do something like that:

mysql_query("CREATE VIEW [test] AS SELECT * FROM table WHERE status=1");

$sel = "SELECT * FROM [test] LIMIT 0,6";

$result = mysql_query($sel);

while($r=mysql_fetch_array($result)){ 
    echo "".$r['id']."<br>";
}

How can I do it? Thanks!

3
  • 1
    Have you tried adding the WHERE clause? There's nothing special, just put it before the LIMIT Commented Feb 10, 2012 at 2:51
  • 2
    I don't understand. What's the problem with $sel = "SELECT * FROM [test] WHERE condition = value LIMIT 0,6"; ???? Commented Feb 10, 2012 at 2:53
  • Simple as that. Actually I was having a problem in other part of my code. That's why the fetch_array wasn't working. Thank you all. Commented Feb 10, 2012 at 3:42

1 Answer 1

1
$query = "SELECT * FROM `table` WHERE this = 'that' ";
$limit = "ORDER BY index LIMIT 6 ";
$result = mysql_query($query.$limit);

You need to limit your ordered conditional selection. (You probably don't have to order this)

Sign up to request clarification or add additional context in comments.

1 Comment

Simple as that. Actually I was having a problem in other part of my code. That's why the fetch_array wasn't working. Thank you all.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.