We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20196
    • 13 Posts
    Hey guys and (girls)
    I need some help here; I'm building a query and for the like of me I don't understand what I'm doing wrong, but you guys to the rescue smiley

    $results = $modx->query("SELECT * FROM modx_deal_product WHERE FIND_IN_SET('".$arr[0]."', collection)");

    This does exactly as intended, great however?

    $results = $modx->query("SELECT * FROM modx_deal_product WHERE FIND_IN_SET('".$arr[0]."', collection)");
    if(count($arr)>1)
    {
    	foreach($arr as $keyword)
    	{
    		$results->orCondition("FIND_IN_SET('".$arr[$keyword]."', collection");	
    	}
    }

    This is generating an error "Fatal error: Call to undefined method PDOStatement::orCondition()".
    Okay, but what is the right syntax for adding conditional OR statements, potentialy several OR conditions.

    Best regards
    Moonkin [ed. note: moonkin last edited this post 13 years, 6 months ago.]
      • 20196
      • 13 Posts
      Hi Guys

      I realize i might not have been too thorough in me post, doesn't matter though as I solved my self. I was looking at the problem all wrong.
      I solved it by building the query string before implementing(in lack of better words) it with $modx->query();

      For people with similar needs, here you go.

      $sqlstr = "";
      $sqlstr .= "SELECT * FROM modx_deal_product WHERE FIND_IN_SET('".$arr[0]."', collection)";
      if(count($arr)>1)
      {
      	foreach($arr as $keyword)
      	{
      		$sqlstr .= "OR FIND_IN_SET('".$arr[$keyword]."', collection)";	
      	}
      }
      $results = $modx->query($sqlstr);