Welcome Guest, Not a member yet? Register   Sign In
Nested Query Question (NEWBIE)
#11

[eluser]sl3dg3hamm3r[/eluser]
Sorry, didn't mean to confuse you. "implements Iterator" means you implement the Iterator interface. This has nothing to do with CI and is pure PHP. See [email=http://php.net/manual/en/class.iterator.php]PHP-Manual[/email], or general information about this Pattern [email=http://en.wikipedia.org/wiki/Iterator_pattern]here[/email]. It belongs to the behaviour patterns.
It simply makes it possible to use "foreach" on your class-instance. This wouldn't be possible otherwise.

I'm not sure if you might fetch all data at once with a left-outer join instead of querying each time in getPrice(). You could then simply check there the fields and returning them depending how they are set.

And oh, if it is only about "if field x is null, then take field y", this you actually also could do within SQL-queries. Then the whole design here might be overcomplicated. But I think it is anyhow a good exercise to see how to encapsulate things, right? Smile
#12

[eluser]JesseR[/eluser]
Yes it is great exercise. I will definently read up on implement iterator.

Also I am going to see what I can do to the database. Since I am using
database from an existing business system I was stuck with its logic
of tables and fields. However I am basically copying the existing
database from its original source of a SQL database to a mySql db
just for the use of this script. So I can make changes to my new copy
of the database basically by writing some queires that run automatically
and place the price in the same table as items, and do a majority of
my logic possibly.

A new challenge I have is this. I have an item that comes in
numerous colors if ITEMS.MATRIX_ITEM_TYPE = 'x' then I need
to show each color as an item on the product page. The below
query accomplishes this but of course I want this set of items
to display in correct order with my other items in the same category.
I might have five items that have five color options and then 20
items in the same category that have no color options.

What would you suggest to accomplish this?

Code:
SELECT
                    ITEMS.CUSTNUM1 AS ITEM_RANK, ITEMS.ITEMNO AS ITEM_NO, CONCAT(ITEMS.DESCRIPT,' ',MATRIX_ATTRIBUTE_ELEMENTS.ELEMENT_DESCRIPTION) AS ITEM_NAME,
                    CONCAT(ITEMS.ITEMNO,'-',MATRIX_ELEMENT_SELECTION.ELEMENT_CODE,'.jpg') AS ITEM_IMAGE, ITEMS.CATEGORY AS ITEM_CATEGORY, ITEMS.MATRIX_ITEM_TYPE AS ITEM_MATRIX_ITEM_TYPE, ITEMS.QTY_STK AS ITEM_STOCK, CATEGORY.CUSTCHAR2 AS CATEGORY_FOLDER, CREAT_DATE AS ITEM_CREATE_DATE,MANUCODE AS ITEM_MANUCODE,BRAND AS ITEM_BRAND,MATRIX_ATTRIBUTE_ELEMENTS.ELEMENT_DESCRIPTION AS ITEM_COLOR,MATRIX_ATTRIBUTE_ELEMENTS.ELEMENT_CODE  AS ITEM_IMAGE_COLOR
                    FROM ITEMS

INNER JOIN MATRIX_ELEMENT_SELECTION ON ITEMS.ITEMNO  = MATRIX_ELEMENT_SELECTION.MATRIX_GROUP_CODE AND MATRIX_ELEMENT_SELECTION.ATTRIBUTE_DESCRIPTION = 'Sanita Color'
INNER JOIN MATRIX_ATTRIBUTE_ELEMENTS ON MATRIX_ELEMENT_SELECTION.ELEMENT_CODE = MATRIX_ATTRIBUTE_ELEMENTS.ELEMENT_CODE AND MATRIX_ATTRIBUTE_ELEMENTS.ATTRIBUTE_DESCRIPTION = MATRIX_ELEMENT_SELECTION.ATTRIBUTE_DESCRIPTION
INNER JOIN CATEGORY ON ITEMS.CATEGORY= CATEGORY.CATEGORY
WHERE ITEMS.CATEGORY = '$c'




Theme © iAndrew 2016 - Forum software by © MyBB