How to create a grid from three mysql tables - php

I am trying to create a grid with yii using three different tables. Here is a rough demonstration of what I am trying to achieve:
Table: Products
prod_id, prod_name
Table: Regions
reg_id, reg_name
Table: Prices
price_id, prod_id, reg_id, price
Products/Regions | Region#1 | Region#2 | ... | Region#N
--------------------------------------------------------
Product#1 | Price#1 | Price#2 | ... | Price#N
Product#2 | Price#1 | Price#2 | ... | Price#N
Product#3 | Price#1 | Price#2 | ... | Price#N
...
Product#N | Price#1 | Price#2 | ... | Price#N
I need to approach this from the products table. I need to be able to search the products. And I don't need to to use GridView, also it would be optimal if I can use it.
I really need recommendation more than anything in this situation. One idea I have is to create a double array of prices and access them and put them in the table $prices[$prod_id][$reg_id] but this system has to be really optimal and performance plays a huge role. So, I would appreciate if anyone can help me out with this.
Thanks,
Gasim

Related

Symfony - Doctrine relationship - Returns relational model with null values

First things first. I am totally new on Symfony, and I am trying to solve an issue but I don't know how. So, if my questions seem to weird to you, then please help me by explaining where I am wrong and thank you in advance.
So, in my DB I have the following tables:
payments, with columns: id, merchant_sevice_id, customer_id, status, type, created_at, amount_amount, amount_currency. payment_method_payment_method_type, payment_method_payment_method_id, vat and failed_reason.
and
merchant_services with columns: id, payment_institution_id, account_id, name, capacity, capabilities, created_at, mid, status, and blocked_bins_id.
The two tables are connected with a manyToOne relationship. So, many payments could belong to one Merchant
Now, the problem is when I try to get one Payment and check the relationship with Merchants. The fields of the Merchant are all nulled, while in DB I have values.
So a given record in payments table looks like that:
| id | merchant_service_id | customer_id | status | type | created_at | amount_amount | amount_currency | payment_method_payment_method_type | payment_method_payment_method_id | vat | failed_reason |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| 0fede82a-b898-4287-83e3-8f7d28d576db | 548d36d9-f1e6-4854-b513-1559b2499b45 | 237369c4-feed-4e24-964a-638938c7940c | failed | SALE | 2018-06-15 07:36:28 | 100 | GBP | card | f35f78c4-2da7-432a-ace5-c0829db448af | 5 | |
And the related record in merchants is like that:
| id | payment_institution_id | account_id | name | capacity | capabilities | created_at | mid | status | blocked_bins_id |
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| 548d36d9-f1e6-4854-b513-1559b2499b45 | c7a02b53-6c8b-4aa9-b1af-1c5b4978d844 | 4d239c0f-1fa0-4d70-88b4-95b6f05e7bf5 | Test | 0 | ["AUTH"] | 2018-06-06 06:36:15 | 53 | active | e3d6a222-68cd-468c-a78a-b0da8ff0caf9 |
Then, the output of my query in the DB seems like that:
As you could see, the values of the merchantService are all null (except the ID).
So the question is, what it could make this problem? Could be a serializer? Is that a kind of Symfony issue? Actually I am looking for a hint on where to look for solution of that issue.
Again sorry if my question is too weired, but I am really blocked and I don't know how to continue.
As iainn indicated in his comment Doctrine relationships are by default lazy-loaded (you can change that by using fetch="EAGER" in the ManyToOne annotation). Indeed, you can easily observe that in your screenshot, as the merchantService object has property __isInitialized__ set to false. That means it is a proxy object of MerchantService class.

how to use codeigniter where in on comma seperated row values

I am using codeigniter for my project and implementing search. I want to filter users from users table with cars they own. Structure of this table is shown below
+-----+----------+---------------------+---------------+
| #id | username | cars | other_details |
+-----+----------+---------------------+---------------+
| 1 | MAC | Jaguar,Porche | -- |
| 2 | DEV | Porche,Ferrari,Ford | -- |
| 3 | MONICA | Ford,Audi | -- |
+-----+----------+---------------------+---------------+
On front end, I am selecting cars from checkboxes which are returning car array for find users who have these cars like ["Porche","Ferrari"]. I am not able to find solution for how to get users using codeigniter active records in model. Please help me find out how to get users/rows having cars available in array.
Thanks in advance.
Finally, I find answer.First I had implode array with comma(,) and then use sql query and regular expression for getting an answer like this;
$this->db->sql("select * from users where `cars` NOT REGEXP '$cars'");
This query give data according to my requirement.

Doctrine multiple 1 to 1 connections

I have task that would be quite simple using regular SQL query but the project is built using doctrine and I am looking for an optimal solution. Maybe someone could advise what would be a good way to approach this.
I have a quite complicated db structure but the simplified version of objects in question look like this:
| Category | | Product | | ProductOption |
------------ --------------- --------------------
| id | | id | | id |
| name | | category_id | | product_id |
------------ | name | | some_data |
--------------- --------------------
Product Option and Product have 1 to 1 connection. But options are created per category (I get 1 entity per category, but need to replicate that entity for every product and store that as 1 to 1 since at some point those options will need to be edited individually. Now there are many ways to do that (the dirty way) , but I would like some advice on how to do that in the most optimal way.

mysql performance and security related issue

I get some issues when i implement product_description table with language .
my process is that i have default table product_description_en to store description and when a client installs new language (Chinese) the php script will create new table product_des_ch and then put the all default data(from the English table) in to the newly created table.then the client can update .
My problems are
Is it a security issue that we create the table dynamically while installing new language
2.If we use same table for all languages(the records will be around 500,000) then are there any per performance issues
3.what is the best way for large amount of records to store , i mean same table or separate tables.
Thanx
Az
Updated:
This is sample product_description table structure for English table and Japan .What you think about this table(we store the all records in a same table and when the client inserts new record for different language only inserting new records ) ,Any feedback please ?
+---------------------------------------------------------------------------+
| product_id | name | desc | meta_name | meta_desc | key_words | lan_code |
+---------------------------------------------------------------------------+
| 1 | A | D| m1 | m_d1 | k1 | en |
+---------------------------------------------------------------------------+
| 1 | A | D| m2 | m_d2 | k2 | jp |
+---------------------------------------------------------------------------+
Basic RDBMS design wisdom would put a huge red flag on anything that dynamically alters the table structure. Relational databases are more than flexible enough to handle pretty much any situation without requiring such measures.
My suggestion as for the structure would be to create a single Languages table to store the available languages, and then a Phrases table to store all the available phrases. Then use a Translations table to provide the actual translations of those phrases into the available languages. Something that might look like this:
Language
+----+---------+
| id | name |
+----+---------+
| 1 | English |
| 2 | Chinese |
+----+---------+
Phrase
+----+-------------+
| id | label |
+----+-------------+
| 1 | header |
| 2 | description |
+----+-------------+
Translations
+-------------+-----------+-----------------+
| language_id | phrase_id | translation |
+-------------+-----------+-----------------+
| 1 | 1 | Header |
| 1 | 2 | Description |
| 2 | 1 | 头 |
| 2 | 2 | 描述 |
+-------------+-----------+-----------------+
For small to medium sized databases, there should be no performance issues at all even using the default database configurations. If you get to huge sizes (where you are counting the database size in terabytes) you can optimize the database in many ways to keep the performance level acceptable.

Laravel: how to make a key of a column name?

I'm bending my mind for some time now over this problem. Could someone please help me?
I have two tables: products and product_attributes. The product has all basic product information and product_attributes has all specific information for products on different categories. It's much like the magenta attribute system. this table has 4 columns: id, product_id, attribute_name, attribute_value.
Now let's say a product has 2 attributes:
------------------------------------------------------
| id | product_id | attribute_name | attribute_value |
------------------------------------------------------
| 1 | 123 | length | 123cm |
------------------------------------------------------
| 2 | 123 | material | Denim |
------------------------------------------------------
| 3 | 123 | season | Summer |
------------------------------------------------------
Now if I set up the eloquent relationships and query a product, I get a product object with all three attributes. So far this is what I wanted. But now in a blade template I would like to be able to do something like this:
$product->attribute->length
Is this even possible or do I need to achieve these kind of things with a total different approach (like creating different tables for different product types/categories)?
Thanks in advance!
length is a tuple value not an attribute you need
$product->attribute->where('attribute_name', 'length')
or
$product->attribute->whereAttributeName('length')

Categories