Welcome Guest, Not a member yet? Register   Sign In
Having trouble updating a joined table
#1

[eluser]baudday[/eluser]
Code:
$priceq = array(
                                        'base' => $prices[0],
                                        'xl' => $prices[1],
                                        'two' => $prices[2],
                                        'three' => $prices[3],
                                        'four' => $prices[4],
                                        'five' => $prices[5]
                                        );
        $this->db->join('shirts', 'shirts.shirtId = prices.shirtId');
        $this->db->where('shirtName', $name);
        $this->db->update('shirts', $priceq);

That's my little snippet of code. I have a prices table and a shirts table. I'm joining them on the ShirtId field. The way I understand it the joined table should have all the columns from the shirts table plus all the columns from the prices table right? I don't know maybe I'm not understanding it correctly, I'm not an SQL pro. Anyway, I'd like to update the prices for the corresponding shirt but I'm having trouble.

I'm having some trouble with this, the error I get is

Unknown column 'base' in 'field list'

I'm at a complete loss. Also, if someone can tell me what type of join to use (left, right, inner, outer) so that all of the shirts table shows up even if it doesn't have a corresponding entry in prices, that'd be great!

Thanks!

P.S. I'm new here and absolutely love codeigniter. It has enabled me to do things so much faster and more easily.
#2

[eluser]WanWizard[/eluser]
May I suggest you read up on SQL before you move on?

JOIN is something you do on selects, not on updates.
#3

[eluser]baudday[/eluser]
Ah okay yeah I don't know much SQL. Thanks! Is there a way to update/insert the way I want to?
#4

[eluser]danmontgomery[/eluser]
It is possible to join on an update query, but for what you're doing it would be simpler to just run 2 update queries.
#5

[eluser]baudday[/eluser]
Okay that's what I did. I appreciate the help!




Theme © iAndrew 2016 - Forum software by © MyBB