I use this class to build my sql statements and things work fine, but I recently turned on all error checking and keep getting: mysql_num_rows() "supplied argument is not a valid MySQL result resource"
When I remove $si['additional'][2] and add the "ORDER BY t1.todo ASC" to the end of $si['additional'][1] the error goes away... but when I display the sql statement, it looks exactly the same, either way... Any ideas?!?! This is driving me nuts. Thanks.
Class:
class getTodos {
public $sql;
function __construct($si = "") {
$this->sql = "SELECT $select
FROM todos AS t1
INNER JOIN todo_cats AS t2 ON t1.todo_cat_id = t2.todo_cat_id
";
if ((isset($si['additional']) && ($si['additional'] != NULL))) {
foreach ($si['additional'] as $i) {
$this->sql .= " $i";
}
}
}
function getSql() {
return $this->sql;
}
function getNumRows() {
$dbConnector = new dbConnector('main');
$query = $dbConnector->query($this->sql);
$num = $dbConnector->getNumRows($query);
return $num;
}
}
In the display page I call the following:
$si = '';
$si['additional'][0] = "WHERE t1.project_id = '$project_id'";
$si['additional'][1] = "AND t1.todo_cat_id = '$todo_cat_id'";
$si['additional'][2] = "ORDER BY t1.todo ASC";
$data = new getTodos($si);
$anyrows = $data->getNumRows();
Generated SQL Output (both ways it looks the same):
SELECT * FROM todos AS t1 INNER JOIN todo_cats AS t2 ON t1.todo_cat_id = t2.todo_cat_id WHERE t1.project_id = '365' AND t1.todo_cat_id = '5' ORDER BY t1.todo ASC