Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Data Model Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

problem with if logic


Go to End


3 Posts   1123 Views

Avatar
J2-Paul

Community Member, 51 Posts

10 June 2010 at 1:17pm

Edited: 10/06/2010 1:29pm

The method below is producting this debug output.

Debug (StudentSearch_Controller->StudentSearchResults() in line 74 of StudentSearch.php)
waldron
Debug (StudentSearch_Controller->StudentSearchResults() in line 85 of StudentSearch.php)
*

...

// Get student search results for display on template
function StudentSearchResults(){

$searchstring=Session::get('SearchString');
Debug::show($searchstring);
if ($searchstring="*") {
$results = DataObject::get('Student','','Lastname,FirstName');
}
else {
$results = DataObject::get('Student',"`Lastname`='".Convert::raw2sql($searchstring)."'",'Lastname,FirstName');

}
Debug::show($searchstring);
return $results;

}

....

It seems to me that the if statement is setting the value of the searchstring.

Any ideas?

Avatar
mark_s

Community Member, 78 Posts

10 June 2010 at 2:48pm

Hi.

It needs to be

if ($searchstring == "*")

There are two equals signs for testing equality. One = is assignment, even in an if-statement.

Mark

Avatar
J2-Paul

Community Member, 51 Posts

10 June 2010 at 8:00pm

Thanks Mark. Do you know, I thought of trying that. Don't know why I didn't! I'm New to PHP and I'm to used to my old foxpro syntax days!

Much appreciated.