Post by Cue4cheap » Wed Aug 06, 2014 10:56 am

I am not a programmer but I would say I am a pretty good hack BUT this one has me completely stumped because reading online how to do what I want makes me think I am reading an alien language.

I have this code to update a product price in the product table:

Code: Select all

 $this->db->query("UPDATE " . DB_PREFIX . "product SET price    = '" . $this->db->escape($dbprice) . "' WHERE ".$column." = '" . $reference . "'");
It works... But researching on trying to add another where clause that also checks the product_to_store table and only update if it finds the product id in a particular store, has me reading things and being lost.
I can get the product_id from the product table without issue so I should be able to take that product_id and check the product_to_store table to see what store that product_id is in.

So I am looking for a simpler tutorial then these:
http://www.w3schools.com/sql/sql_join.asp

I am wishing to learn so please don't give me complete code. I know that might be what lots of folks are searching for but that would help me in the short term but I would be back to bug you all on a later issue so I would rather be pointed to an example.

Thanks!
Mike

cue4cheap not cheap quality


Expert Member

Posts

Joined
Fri Sep 20, 2013 4:45 am

Post by Cue4cheap » Sat Aug 09, 2014 5:56 am

Any thoughts or pointers to a good tutorial?

Thank you,
Mike

cue4cheap not cheap quality


Expert Member

Posts

Joined
Fri Sep 20, 2013 4:45 am

Post by Cue4cheap » Sun Aug 10, 2014 1:17 am

Well I am trying without the join statements but I am confused by what I am trying:

Code: Select all

$q2 = "SELECT product.product_id, product_to_store.store_id FROM " . DB_PREFIX . "product, product_to_store WHERE product.product_id=$productId AND product_to_store.store_id=0";
$result2 = $this->db->query( $q2 );
When I echo out $q2 it equals:

Code: Select all

SELECT product.product_id, product_to_store.store_id FROM product, product_to_store WHERE product.product_id=96 AND product_to_store.store_id=0
So the $productId is being sent, in this case 96.

My thought is I should be able to echo $result2 and be able to see what is being returned by the query but the echo give me nothing.
In the product_to_store table product_id 96 is in the table for store 0 and 1.
What am I missing?
Mike

cue4cheap not cheap quality


Expert Member

Posts

Joined
Fri Sep 20, 2013 4:45 am

Post by Cue4cheap » Mon Aug 11, 2014 2:28 am

I decided to make things easy on myself. I went about this a different way and have it working 97%.

I still have no clue why this code

Code: Select all

SELECT product.product_id, product_to_store.store_id FROM product, product_to_store WHERE product.product_id=96 AND product_to_store.store_id=0
gives so many rows returned; it returns 100s of records.

Mike

cue4cheap not cheap quality


Expert Member

Posts

Joined
Fri Sep 20, 2013 4:45 am

Post by SXGuy » Mon Aug 11, 2014 5:38 am

not sure what you are trying to achieve. But I believe this "should" be formatted correctly.

Code: Select all

$result = $this->db->query("SELECT `" . DB_PREFIX . "product.product_id, `" . DB_PREFIX . "product_to_store.store_id` WHERE product_id = '". $productId . "' AND store_id=0");

Active Member

Posts

Joined
Sun Nov 08, 2009 2:07 am
Who is online

Users browsing this forum: No registered users and 65 guests