Gentlemen, you need help in formulating a request to the database, or maybe advice on how to organize everything more competently. Given 2 sql tables in the first stored data on the drawings table format id | ch | onop | twop | thop | thop | in the columns | onop | twop | thop | contain rates for each operation. The second table is a report for the day (history) using data from the first table in the format | operator | detal | operaciya | cena | which is filled from the usual web form from selects and one drop-down list from the database. Here is the question, the whole thing is displayed in the html face and everything would be great, but you need to write down the price of the operation of each product, and here I told how to do this without a clue. Everything is written in history remarkably through joins, but the variable from the select with the choice of operation is written in the database with the name of the column. I just need good advice or at least some kind of help, I rummaged through a lot of literature on sql and pkhp and killed it for a week already, although I am sure that it is easier to implement
2 answers
You have two tables:
The first (table1) describes the details, fill it only with details.
In the second (table2) operation, write the type of operations into it, indicating in the detal column (id of the first column)
When outputting, do a cross-query for the example like this:
SELECT table2.* FROM table2 LEFT JOIN table1 ON table1.id=table2.detal Well, output the result.
- I thought in this direction, but the question was how to put a face into the web, there is a table in which data is taken through a join based on a history table with columns | date | operator | details | price / item | and I donβt know how to slip the price into this table, or rephrase if you tell the script to take data from the column from the second operation, for example - freakrock
- In this table I print
$strSQL = "select * from chertesh,cnc where detal=id iner "; $res = mysql_query($strSQL); while($row = mysql_fetch_array($res)) {$strSQL = "select * from chertesh,cnc where detal=id iner "; $res = mysql_query($strSQL); while($row = mysql_fetch_array($res)) {$strSQL = "select * from chertesh,cnc where detal=id iner "; $res = mysql_query($strSQL); while($row = mysql_fetch_array($res)) {echo '<tr> and through the row in each column its data, in general, everything is correctly displayed, but how can I not insert my mind here for the price - freakrock - So from the above, I see that the data from the second table is not taken. $ strSQL = "select * from chertesh LEFT JOIN chertesh ON chertesh.id = cnc.detal where detal = id"; So try and add a column cena - Ruslan Semenov
- In general, I came out
select * from oi JOIN chertesh ON id = id_ch where id_ch=idand yes you were right the columns appeared but with them there was a question now I have output | onop | twop | thop | Let's say, how can we now attach an operaciya column to them from the history table where the number of this operation is recorded so that only one value we need is displayed as a result. Or it may be better to change the values ββin the operation select list now there are stupid names of operation columns, that is, onop, twop . - freakrock - or now I decided to try a workaround in the script of the history fill handler to immediately replace the values ββwith variables and find the required
$cena = mysql_query(" select '".$operaciya."'from oi LEFT JOIN chertesh ON id =" ". $ detal." '"); $ cena = $ _ POST ['cena']; $ result = mysql_query ("INSERT INTO cnc (operatorname, cena, operaciya, detal, colvodetal, brakop, data, brakotk) VALUES ('". $ operatorname. "', '". $ cena. "', '". $ operaciya. "','". $ detal. "','". $ colvodetal. "','". $ brakop. "','". $ data. "','". $ brakotk. "') ");` but it was a fiasco here, the request works in the admin and not in the script ( - freakrock
In general, I won the task by adding another table that indicates which data belongs to which operation, but it is not the easiest way to work. I make a selection: select * from |ΡΠ°Π±Π»ΠΈΡΠ° ΡΠΊΠ°Π·ΡΠ²Π°ΡΡΠ°Ρ ΠΊΠ°ΠΊΠΎΠΌΡ ΡΠ΅ΡΡΠ΅ΠΆΡ ΠΊΠ°ΠΊΡΡ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΡ Π±ΡΠ°ΡΡ| , |ΡΠ°Π±Π»ΠΈΡΠ° Ρ "ΠΈΡΡΠΎΡΠΈΠ΅ΠΉ"| LEFT JOIN |ΡΠ°Π±Π»ΠΈΡΠ° ΡΠΎ ΡΠΏΠΈΡΠΊΠΎΠΌ ΡΠ΅ΡΡΠ΅ΠΆΠ΅ΠΉ| ON |id Π΄Π΅ΡΠ°Π»ΠΈ| = id left join |Π½ΠΎΠΌΠ΅Ρ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΈ| on |ΠΎΠΏΠ΅ΡΠ°ΡΠΈΡ ΠΈΠ· ΠΈΡΡΠΎΡΠΈΠΈ| = |id ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΈ Ρ ΡΠ°Π±Π»ΠΈΡΠ΅ΠΉ ΡΠΊΠ°Π·ΡΠ²Π°ΡΡΠ΅ΠΉ ΠΊΠ°ΠΊΠΎΠ΅ Π·Π½Π°ΡΠ΅Π½ΠΈΠ΅ Ρ ΠΊΠ°ΠΆΠ΄ΠΎΠΉ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΈ| select * from |ΡΠ°Π±Π»ΠΈΡΠ° ΡΠΊΠ°Π·ΡΠ²Π°ΡΡΠ°Ρ ΠΊΠ°ΠΊΠΎΠΌΡ ΡΠ΅ΡΡΠ΅ΠΆΡ ΠΊΠ°ΠΊΡΡ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΡ Π±ΡΠ°ΡΡ| , |ΡΠ°Π±Π»ΠΈΡΠ° Ρ "ΠΈΡΡΠΎΡΠΈΠ΅ΠΉ"| LEFT JOIN |ΡΠ°Π±Π»ΠΈΡΠ° ΡΠΎ ΡΠΏΠΈΡΠΊΠΎΠΌ ΡΠ΅ΡΡΠ΅ΠΆΠ΅ΠΉ| ON |id Π΄Π΅ΡΠ°Π»ΠΈ| = id left join |Π½ΠΎΠΌΠ΅Ρ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΈ| on |ΠΎΠΏΠ΅ΡΠ°ΡΠΈΡ ΠΈΠ· ΠΈΡΡΠΎΡΠΈΠΈ| = |id ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΈ Ρ ΡΠ°Π±Π»ΠΈΡΠ΅ΠΉ ΡΠΊΠ°Π·ΡΠ²Π°ΡΡΠ΅ΠΉ ΠΊΠ°ΠΊΠΎΠ΅ Π·Π½Π°ΡΠ΅Π½ΠΈΠ΅ Ρ ΠΊΠ°ΠΆΠ΄ΠΎΠΉ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΈ| I think it will be necessary for someone who understood exactly what I wanted to achieve) Thank you for the rest and especially Ruslan_Semenov for the tip on Left Join