1
$query = "SELECT a.*, cc.name AS category, dd.ezcity AS proploc, ee.name AS statename, ff.name AS cnname, ss.dealer_name AS propseller, u.name AS editor"

. "\n FROM #__ezrealty AS a"

. "\n LEFT JOIN #__ezrealty_catg AS cc ON cc.id = a.cid"

. "\n LEFT JOIN #__ezrealty_locality AS dd ON dd.id = a.locid"

. "\n LEFT JOIN #__ezrealty_state AS ee ON ee.id = a.stid"

. "\n LEFT JOIN #__ezrealty_country AS ff ON ff.id = a.cnid"

. "\n LEFT JOIN #__ezrealty_profile AS ss ON ss.mid = a.owner"

. "\n LEFT JOIN #__users AS u ON u.id = a.checked_out"

. ( count( $where ) ? "\n WHERE " . implode( ' AND ', $where ) : "")

. if ( isset ($_POST['idSearch']) ) 

    . { " WHERE a.id = " . $_POST['idSearch']  ; }

. "\n ORDER BY ". $order

. "\n LIMIT $pageNav->limitstart, $pageNav->limit"

;

i don get the wrong syntax here :( ,, and it keep return the same error unexpected T_IF

1
  • . (!empty($_POST['idSearch']) ? " WHERE a.id = " . $_POST['idSearch'] : "\n ORDER BY ". $order ."\n LIMIT $pageNav->limitstart, $pageNav->limit"); This is the right solution to search in the all pages not only the displayed one Commented Dec 22, 2011 at 8:38

4 Answers 4

3

Remove the . (point) before the if-statement. Because the if-statement itself isn't a string you can't just concatenate it.

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

Comments

2

Don't do this:

. if (condition) { value_if_true; }

Instead do this:

. (condition ? value_if_true : value_if_false)

Comments

1

if can only ever be a statement: you are using it as an expression. It doesn't return anything, and it cannot be used within another statement.

You can, however, use the ternary operator to do exactly this:

. ( isset ($_POST['idSearch']) ?  " WHERE a.id = " . $_POST['idSearch'] : '') 

This says "if $_POST['idSearch'] is set, add that string, otherwise, add the empty string.

Note that you should really look at your code, because there is a glaring SQL injection in just the code that I've posted above. Anyone could execute arbitrary code on your database. Make sure to sanitise your input and, preferably, adopt prepared statements and parameterised queries to make your code more secure.

3 Comments

SQL=SELECT a.*, cc.name AS category, dd.ezcity AS proploc, ee.name AS statename, ff.name AS cnname, ss.dealer_name AS propseller, u.name AS editor FROM jos_ezrealty AS a LEFT JOIN jos_ezrealty_catg AS cc ON cc.id = a.cid LEFT JOIN jos_ezrealty_locality AS dd ON dd.id = a.locid LEFT JOIN jos_ezrealty_state AS ee ON ee.id = a.stid LEFT JOIN jos_ezrealty_country AS ff ON ff.id = a.cnid LEFT JOIN jos_ezrealty_profile AS ss ON ss.mid = a.owner LEFT JOIN jos_users AS u ON u.id = a.checked_out WHERE a.id = ORDER BY a.id DESC LIMIT 0, 5
I'm not quite sure how I'm supposed to debug that, but my guess is that $_POST['idSearch'] is set but empty. I could be wrong. You aren't exactly giving a lot of details...
it is empty ,, it is suppose if it is empty do nothing and retrieve the all data not the specific one ,, i think i will get the post by hyper link and query string :) , thnx all
0

I believe you want to turn this into an evil ternary operator:

. (count ...)
. (isset($_POST['idSearch']) ? ' WHERE a.id = ' . $_POST['idSearch'] : '')
. "\n ORDER BY" ...

2 Comments

Why is the ternary operator evil?
@Rocket I don't think it is, but there are plenty of developers that do. One example of a problem is that you can't add operations to the condition after the fact.

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.