Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] php activerecord query help
#1

[eluser]theprodigy[/eluser]
PHP 5.3.6
MySQL 5.1.52
PHP-AR (from Spark)

I have a search form that spans multiple related tables ($a->$b->$c).

My table layout is:

Code:
CREATE TABLE `tutors` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(255) NOT NULL,
  `password` varchar(255) NOT NULL,
  `f_name` varchar(255) NOT NULL,
  `l_name` varchar(255) NOT NULL,
  `email` varchar(255) NOT NULL,
  `city` varchar(255) NOT NULL,
  `state` varchar(255) NOT NULL,
  `bio` text NOT NULL,
  `url_identifier` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
)

CREATE TABLE `tutor_prefs` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `tutor_id` int(11) NOT NULL,
  `allow_groups` tinyint(1) NOT NULL DEFAULT '0',
  `individual_price` decimal(5,2) NOT NULL,
  `group_per_price` decimal(5,2) NOT NULL,
  `subject` varchar(255) NOT NULL,
  `grade_level_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
)


CREATE TABLE `tutor_reviews` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `tutor_pref_id` int(11) NOT NULL,
  `user_id` int(11) NOT NULL,
  `rating` decimal(3,2) NOT NULL,
  `review` text NOT NULL,
  PRIMARY KEY (`id`)
)

The code I have that is producing an error is (in the Tutor.php model):

Code:
public static function get_search()
{
    $CI =& get_instance();

    $subject = $CI->input->post('subject');
    $price = $CI->input->post('price');
    $city = $CI->input->post('city');
    $state = $CI->input->post('state');
    $stars = $CI->input->post('stars');

    $search_criteria = array();
    $conditions = array();
    $conditions[] = ''; //first element for $search_criteria
    $params = array();

    $join = array();

    //array('conditions' => array('genre = ? AND price < ?', 'Romance', 15.00))

    if($subject)
    {
        $search_criteria[] = 'tutor_prefs.subject like ?';
        $conditions[] = '%'.$subject.'%';
        $join = 'prefs';
    }

    if($price)
    {
        $search_criteria[] = '(tutor_prefs.individual_price = ? OR tutor_prefs.group_per_price = ?)';
        $conditions[] = $price;
        $conditions[] = $price;
        $join = 'prefs';
    }

    if($city)
    {
        $search_criteria['city'] = $city;
    }

    if($state)
    {
        $search_criteria['state'] = $state;
    }

    if($stars)
    {
        $search_criteria[] = 'tutor_reviews.rating = ?';
        $conditions[] = $stars;
        $join = 'reviews';
    }

    if(count($join) > 0)
    {
        $params['joins'] = $join;
    }

    if(count($search_criteria) > 0)
    {
        $conditions[0] = implode(' AND ', $search_criteria);
        $params['conditions'] = $conditions;
    }

    return Tutor::all($params);
}

The error being produced is
Uncaught exception 'ActiveRecord\DatabaseException' with message '42S02, 1051, Unknown table 'tutors''

All other functions in this class work just fine, it is just this one function/method.

Any help is greatly appreciated.

Thanks.




Theme © iAndrew 2016 - Forum software by © MyBB