I am trying to use a SELECT statement to call in some information.

CODE: $qry = $this->EE->db->query('SELECT col_id_1, col_id_2, col_id_3 FROM exp_matrix_data');

I get this error when I try to use the data:

A PHP Error was encountered Severity: Warning Message: mysql_num_rows() expects parameter 1 to be resource, string given Filename: libraries/Functions.php(680) : eval()'d code Line Number: 1552

So... my question is, Can I not use the 'SELECT Statement' like this in EE ?

  • Have you tried building this using the Query module?
    – Lisa
    Mar 26, 2013 at 21:08

1 Answer 1


You would need to either turn on PHP for the template and then use that to create a query like you did, or go the much easier route an just use the Query Module included with ExpressionEngine (unless you are using Core).

With the Query Module your statement would look like

{exp:query sql="SELECT col_id_1, col_id_2, col_id_3 FROM exp_matrix_data"}

Remember to add limits and sorts as needed. You can learn more about the Query Module in the User Guide.

  • PHP is ON in my template. The problem I now encounter (when I use Query Module) is that when I add my 'Limit' by way of a WHERE/IN Clause like this: {exp:query sql='SELECT col_id_1, col_id_2, col_id_3 FROM exp_matrix_data WHERE col_id_3 IN($postNameJoined)'}. Of course I get a syntax error. I am not actually sure if I am in PHP or not at that point of the code? NOTE:The Variable is created from an array of some posted information on the page, so I don't think I can pull it in from anywhere else. Any advice on adding a variable to the "IN" part of the Where clause would be greatly appreciated?
    – JayB
    Mar 27, 2013 at 15:39
  • You don't need PHP on with the Query Module, unless the variable you are searching on is passed via PHP. I'm not certain what your $postNameJoined is collecting. Normally, we do either a manual IN() or a subquery. It sounds like you may need a subquery, but I can't figure out what $postNameJoined should represent. Mar 27, 2013 at 16:49
  • Thanks for your time! I am using php to pull strings from $_POST data, into an array, then joining them. This is where I get the '$postNameJoined' to use in the WHERE/IN Clause. I will later have to compare the 'filtered' col_id_1 & col_id_2 results in a 'php' foreach loop, that keeps col_id_2's key ahead by one, to return my final result. The entire problem is that I am trying to validate start and end times of selected events so that there is no overlap in selections. SO, when I'm in the exp:query tag I can't use php? I can't think of another way to filter my results. Ideas?
    – JayB
    Mar 27, 2013 at 17:56
  • You can use PHP in the Query tag, but you'll need to be careful about Input vs Output stages. For example, if you need EE to provide you data, so you can use it in the Query, then that can be a problem, see ellislab.com/expressionengine/user-guide/templates/php.html but if information is directly from PHP to be used, then I believe you want parse on input. Maybe if you send an email allgood2 on Gmail. I need a better idea of what pull strings from $_POST data is EE fields, date, category, event_type, etc. Is it passed via url_segment, pull from different data table? Send email. Mar 27, 2013 at 20:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.