1

I have a general understanding of what I would like to do but not sure how to write the SQL.

Users have the ability from changing the sort from ASC to DESC and increase the query limit from 5 to 10.

$result=$mysqli->query("SELECT * FROM table WHERE status = 3 ORDER BY name ASC LIMIT $start_from, 5");

the option box for asc/desc will end up being $sort_order the option box for limit will be $limita

I tried to write it like

$result = "SELECT * FROM wp_pod_tbl_bars WHERE status = 3";
 if(!empty($limita)){$result.="LIMIT $limita, 5";}
 if ($result = $mysqli->query($result)) { 
 while($row = $result->fetch_object()){ 

but the query ended up empty due to the query being split into different lines.

Any idea what I am doing wrong? ill post more code if needed but this is generally where my issue is.

1 Answer 1

1

Put space between status and LIMIT.

$result = "SELECT * FROM wp_pod_tbl_bars WHERE status = 3";
 if(!empty($limita)){$result.=" LIMIT '".$limita."', 5";}
                ---------------^
Sign up to request clarification or add additional context in comments.

2 Comments

Wow that little space makes all the difference thanks! Have to wait 10 minutes to accept it as the answer. But I will!
Yes, I can't believe that space is what stopped it.

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.