Hello,
I have been updating an old website to an all new install.
I have managed to update basic connections from an OLD CC (I think it is v3) to CCv5 but I am struggling to get my head around how to do something like the below.
So just to explain a little, the first part echoes the "WHERE" statement and the second part echoes the "AND" statement as they both have variables. You would end up with "WHERE x = x" then "AND y=y" echoed separately.
I understand how to convert them separately but I am unsure as to how I would join them as things are no longer echoed.
Any help on how to convert this to a new WHERE condition would be greatly appreciated. I think once I work this out things might click better.
Hope this makes sense.
Thanks in advance.
I have been updating an old website to an all new install.
I have managed to update basic connections from an OLD CC (I think it is v3) to CCv5 but I am struggling to get my head around how to do something like the below.
<?php
$user =& JFactory::getUser();
$username = "{$user->username}";
$agent = JRequest::getString('agent', '', 'post');
if ($username == "FUW123" && $agent=="") {
echo "WHERE `brokerid` = 'NOUSERAME'";
}else if ($username == "FUW123" && $agent) {
echo "WHERE `agent_name` LIKE '%$agent%' ";
}else if ($username !="FUW123"){
echo "WHERE `brokerid` = '{$user->username}'";
}
?>
<?php
$title = JRequest::getString('title', '', 'post');
$name = JRequest::getString('name', '', 'post');
if ( $title && $name=="") {
echo " AND `houshold` LIKE '%$title%' ";
}else if ( $title=="" && $name ) {
echo " AND `clientforename` LIKE '%$name%' ";
}else if ( $title && $name ) {
echo " AND `clientforename` LIKE '%$name%' AND `houshold` LIKE '%$title%' ";
}
?>
So just to explain a little, the first part echoes the "WHERE" statement and the second part echoes the "AND" statement as they both have variables. You would end up with "WHERE x = x" then "AND y=y" echoed separately.
I understand how to convert them separately but I am unsure as to how I would join them as things are no longer echoed.
Any help on how to convert this to a new WHERE condition would be greatly appreciated. I think once I work this out things might click better.
Hope this makes sense.
Thanks in advance.
Hi ctrlmedia,
The main differences are that you need to return an array rather than echo, and the WHERE is no longer needed. So the first example will be something like this:
Please see this FAQ - though in this case I have built the array using the $return['key'] = 'value'; syntax.
Bob
The main differences are that you need to return an array rather than echo, and the WHERE is no longer needed. So the first example will be something like this:
<?php
$user = \JFactory::getUser();
$agent = \JRequest::getString('agent', '', 'post');
$title = \JRequest::getString('title', '', 'post');
$name = \JRequest::getString('name', '', 'post');
$return = array();
if ( $user->username == 'FUW123' && $agent == "" ) {
$return['brokerid'] = 'NOUSERAME';
} elseif ( $user->username == 'FUW123' && $agent ) {
$return['agent_name LIKE'] = '%'.$agent.'%';
} elseif ( $user->username != 'FUW123' ) {
$return['brokerid'] = $user->username;
}
if ( $title && $name == "") {
$return['houshold LIKE'] = '%'.$title.'%';
} elseif ( $title == "" && $name ) {
$return['clientforename LIKE'] ='%'.$name.'%';
} elseif ( $title && $name ) {
$return['houshold LIKE'] = '%'.$title.'%';
$return['clientforename LIKE'] = '%'.$name.'%';
}
if ( count($return) ) {
return $return;
} else {
// the return array is empty
return false;
}
?>
!! not tested !!
Please see this FAQ - though in this case I have built the array using the $return['key'] = 'value'; syntax.
Bob
Hi Greyhead,
I think that has worked a treat thanks!
I was thinking that the first "$return['brokerid'] = 'NOUSERAME';" was like a WHERE statement and then I needed to add some code that was like an AND statement later on.
So I can return as many things as I like and it will treat them like "WHERE x AND x AND x AND x" automatically.
Probably doesn't make sense but I think it is starting too with me.
Thanks again.
I think that has worked a treat thanks!
I was thinking that the first "$return['brokerid'] = 'NOUSERAME';" was like a WHERE statement and then I needed to add some code that was like an AND statement later on.
So I can return as many things as I like and it will treat them like "WHERE x AND x AND x AND x" automatically.
Probably doesn't make sense but I think it is starting too with me.
Thanks again.
Hi ctrlmedia,
That's pretty much correct for AND statements. For `col_a` = 'xxx' AND `col_b = `yyy' you use
Bob
That's pretty much correct for AND statements. For `col_a` = 'xxx' AND `col_b = `yyy' you use
return array(
'col_a' => 'xxx',
'col_b' => 'yyy'
);
Bob
Hi Bob,
Using your example above using $return['key'] = 'value'; syntax, how would I search between dates?
I tried adding this but it doesn't work.
Thanks in advance.
Regards
Mark
Using your example above using $return['key'] = 'value'; syntax, how would I search between dates?
I tried adding this but it doesn't work.
$return['cf_created >='] => '2016-11-01' ;
$return['cf_created <='] => '2016-11-10' ;
Thanks in advance.
Regards
Mark
This topic is locked and no more replies can be posted.