Jump to:

3430 Posts in 1057 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » problem with if logic

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

Page: 1
Go to End
Author Topic: 823 Views
  • J2-Paul
    Avatar
    Community Member
    51 Posts

    problem with if logic Link to this post

    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?

  • mark_s
    Avatar
    Community Member
    78 Posts

    Re: problem with if logic Link to this post

    Hi.

    It needs to be

    if ($searchstring == "*")

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

    Mark

  • J2-Paul
    Avatar
    Community Member
    51 Posts

    Re: problem with if logic Link to this post

    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.

    823 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.