Welcome Guest, Not a member yet? Register   Sign In
variable number of fields to query joined tables
#1

[eluser]fourcs[/eluser]
I'm trying to develop an application that allows users to choose one or more fields with which to query from two joined tables, joined on a common field. Can someone give me some ideas? I've got a model, controller, user field selection and result views. I'm using active record commands that dynamically fabricate the sql with the user's field selection. I've got the user input form to show. But I'm having difficulty getting the sql to put out the results of the query in the results view.
#2

[eluser]TheFuzzy0ne[/eluser]
Please post your code.
#3

[eluser]fourcs[/eluser]
attached zip file contains the model, controller, and two views.
#4

[eluser]TheFuzzy0ne[/eluser]
Sorry for being thick, but I still don't understand the problem. Please could you explain a bit more?
#5

[eluser]fourcs[/eluser]
All I want to do is provide a viewer the ability to select one or more fields from five or so fields with which to search two tables joined by a common field and present the result of the search in a view. Problem is the sql isn't being conducted in a manner to feed the results view. Also, I'm getting an ambiguous field error for dt_start and dt_end, which, I admit, exist in both tables for different events. But I'm only specifying these fields from one table. Apparently, mysql is saying there's confusion because these two fields occur in both tables and is confused, even though I'm selecting them from only one table. Thanks for your attention. ;-)
#6

[eluser]TheFuzzy0ne[/eluser]
OK, let's say I have two tables (table1 and table2), both with an id field, you may end up with ambiguities as MySQL doesn't know to which id field you're referring to. To help with this, you can prefix your select statement with the table name:

Code:
$this->db->select('table1.id');

Does this solve your problem?
#7

[eluser]fourcs[/eluser]
My select statement in the model did that.
Then the sql statement went on to handle possible fields for searching with the following:



Code:
function records_getall()
  {
    $this->load->database();
  
    $this->db->select("
               records.category,
               records.beds,                
               records.normal_Price,
               records.dt_start,
               records.dt_end,
               records.sb_Price"
               );

    $this->db->or_like('dt_start','match');
    $this->db->or_like('dt_end','match');
    $this->db->or_like('category','match');
    $this->db->or_like('beds','match');
    $this->db->or_like('sb_Price_Range','match');
  
    $this->db->from('records');

    $query = $this->db->get();
    return $query->result();
   }

and is supposed to search the table for matched input field values.
#8

[eluser]TheFuzzy0ne[/eluser]
You still need to use the same thing there, too. Unless of course you're using aliases, which you're not.




Theme © iAndrew 2016 - Forum software by © MyBB