In SiteController.php I have added a function actionSearch() which has several lines like if(isset($_GET[‘txtKeyword’]) && trim($_GET[‘txtKeyword’]) != “”){…
In two different search forms in my site the user entered search would generate different query string variables. A couple of which are
My question is that would yii be able to detect which controller and action to pass the different query strings from two or three different forms giving different query strings
Another question is if I use this
<form action=’/site/search’ method=“get” … it shows me Not Found page. The URL is
Another problem I’m having is with the where clause. I start my where clause with a variable $whereClause="1=1 “; then $whereClause .= " serviceTypeId=” . $_GET[‘serviceTypeId’] . " And "; and so on.
I get this error CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; The SQL statement executed was: SELECT unitlistings.*
FROM unitlistings
WHERE 1 sellprice <= 50000000 AND status = ‘available’ AND 1=1
I need WHERE 1=1 at the start. If I use $whereClause=""; I get WHERE 0 which is also an sql error.
I’m also not getting the whereClause inside this conditional
if(isset($_GET['category']) && trim($_GET['category']) != ""){
$whereClause += " minorCategoryId IN ( " . urldecode($_GET['category']) . " ) AND ";
}
. The query string shows category=35%2C36%2C37%2C40 when the form is submitted
First of l would like to tell you that if you are specifying url hardcoded something as you have mentioned in your post then its not a good approach. You should use
Yii::app()->createAbsoluteUrl()
to define a url. if you are using plan html forms and not creating a form with CActive form class.
And for your next question related to Sql statement,
I got the error, $whereClause += should be $whereClause .=
I’m using 1=1 because I have many conditionals in my code so I start with the variable $whereClause = "1=1 AND "; and then do $whereClause .= inside if else statements to get the final sql query as WHERE 1=1 AND … but I’m getting error because of WHERE 1 AND … Not getting 1=1. Why ?