Welcome Guest, Not a member yet? Register   Sign In
ActiveRecord Expert Needed!
#1

[eluser]btray77[/eluser]
I need an ActiveRecord Expert.. I'm completely lost...

Here's the code I have so far, and I've included the database structure (not my choice on the structure)

I need to be able to perform CRUD functions products based off there SKU, which is a meta value in the productmeta table.

Currently get_many_products gives me a list of products based off of the productmeta id and I've not been able to figure out how to stop this. When it does this it repeats the same product data from the product_list table multiple times. I need to use the product_list id and show all the productmeta information associated with that ID.

At the end there is an example of the current output.

If someone could help me with this I would be eternally grateful...


Code:
function delete_prodcut($id)
        {
            //$tables = array('productmeta', 'product_list');
            $this->db->delete('productmeta', array('product_id' => $id));
            $this->db->delete('product_list', array('id' => $id));
        }


        function get_many_products($num = 10)
        {
            //$tables = array('productmeta','product_list');
            $this->db->select('*');
            $this->db->from('product_list');
            //$this->db->from($tables);
            $this->db->join('productmeta', 'product_list.id = productmeta.product_id','right');        
            //$this->db->where('meta_key = "sku"');
            $this->db->limit($num);
            //$this->db->where('product_list.id = productmeta.product_id ');
            $query = $this->db->get();
        
            if ( $query->num_rows() > 0 )
            {
                return $query->result();
            }
            
            return array();
        }



Code:
--
-- Table structure for table `productmeta`
--

CREATE TABLE IF NOT EXISTS `productmeta` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `product_id` bigint(20) unsigned NOT NULL DEFAULT '0',
  `meta_key` varchar(255) DEFAULT '',
  `meta_value` longtext,
  `custom` varchar(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  KEY `product_id` (`product_id`),
  KEY `meta_key` (`meta_key`),
  KEY `custom` (`custom`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=199 ;

--
-- Dumping data for table `productmeta`
--

INSERT INTO `productmeta` (`id`, `product_id`, `meta_key`, `meta_value`, `custom`) VALUES
(1, 1, 'url_name', 'test-prodcut', '0'),
(2, 1, 'sku', 'Test 1', '0'),
(3, 1, 'table_rate_price', '', '0'),
(4, 1, 'custom_tax', '8.25', '0'),
(5, 1, 'engraved', '0', '0'),
(6, 1, 'can_have_uploaded_image', '0', '0'),
(7, 1, 'external_link', 'http://www.website.com', '0'),
(8, 1, 'thumbnail_width', '96', '0'),
(9, 1, 'thumbnail_height', '96', '0');


--
-- Table structure for table `product_list`
--

CREATE TABLE IF NOT EXISTS `product_list` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `name` text NOT NULL,
  `description` longtext NOT NULL,
  `additional_description` longtext NOT NULL,
  `price` decimal(11,2) NOT NULL DEFAULT '0.00',
  `weight` float NOT NULL DEFAULT '0',
  `weight_unit` varchar(10) NOT NULL DEFAULT '',
  `pnp` decimal(11,2) NOT NULL DEFAULT '0.00',
  `international_pnp` decimal(11,2) NOT NULL DEFAULT '0.00',
  `file` bigint(20) unsigned NOT NULL DEFAULT '0',
  `image` bigint(20) unsigned DEFAULT NULL,
  `quantity_limited` varchar(1) NOT NULL DEFAULT '',
  `quantity` int(10) unsigned NOT NULL DEFAULT '0',
  `special` varchar(1) NOT NULL DEFAULT '0',
  `special_price` decimal(11,2) NOT NULL DEFAULT '0.00',
  `display_frontpage` varchar(1) NOT NULL DEFAULT '0',
  `notax` varchar(1) NOT NULL DEFAULT '0',
  `publish` varchar(1) NOT NULL DEFAULT '1',
  `active` varchar(1) NOT NULL DEFAULT '1',
  `donation` varchar(1) NOT NULL DEFAULT '0',
  `no_shipping` varchar(1) NOT NULL DEFAULT '0',
  `thumbnail_image` text,
  `thumbnail_state` int(11) NOT NULL DEFAULT '0',
  `date_added` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=23 ;

--
-- Dumping data for table `product_list`
--

INSERT INTO `product_list` (`id`, `name`, `description`, `additional_description`, `price`, `weight`, `weight_unit`, `pnp`, `international_pnp`, `file`, `image`, `quantity_limited`, `quantity`, `special`, `special_price`, `display_frontpage`, `notax`, `publish`, `active`, `donation`, `no_shipping`, `thumbnail_image`, `thumbnail_state`, `date_added`) VALUES
(22, 'Test Prodcut 22', 'this is a test prodcut', '', '1233.00', 5, 'pound', '19.95', '85.95', 0, 4, '0', 0, '0', '1110.00', '0', '0', '1', '1', '0', '0', NULL, 0, '2009-08-19 22:51:05');


Current Output

Code:
[0] => stdClass Object
        (
            [id] => 1
            [name] => Test Prodcut 1
            [description] => this is a test prodcut
            [additional_description] =>
            [price] => 1233.00
            [weight] => 5
            [weight_unit] => pound
            [pnp] => 19.95
            [international_pnp] => 85.95
            [file] => 0
            [image] => 4
            [quantity_limited] => 0
            [quantity] => 0
            [special] => 0
            [special_price] => 1110.00
            [display_frontpage] => 0
            [notax] => 0
            [publish] => 1
            [active] => 1
            [donation] => 0
            [no_shipping] => 0
            [thumbnail_image] =>
            [thumbnail_state] => 0
            [date_added] => 2009-08-19 22:49:13
            [product_id] => 1
            [meta_key] => url_name
            [meta_value] => test-prodcut
            [custom] => 0
        )
I would like it to list out all the meta_key's and values associated with that id.


Thanks

-Brad


Messages In This Thread
ActiveRecord Expert Needed! - by El Forum - 08-20-2009, 12:28 AM
ActiveRecord Expert Needed! - by El Forum - 08-20-2009, 01:11 AM
ActiveRecord Expert Needed! - by El Forum - 08-20-2009, 01:21 AM
ActiveRecord Expert Needed! - by El Forum - 08-20-2009, 01:33 AM
ActiveRecord Expert Needed! - by El Forum - 08-20-2009, 01:36 AM
ActiveRecord Expert Needed! - by El Forum - 08-20-2009, 01:39 AM
ActiveRecord Expert Needed! - by El Forum - 08-20-2009, 02:11 PM



Theme © iAndrew 2016 - Forum software by © MyBB