how can I associate one variable with the other two (mysql)? - javascript

I have four tables in mysql (object, type, price, date)
all of them have two coloumns: "id" and "variable"
for example:
Object table
+----+-----------+
| id | variable |
+----+-----------+
| 1 | shop1 |
+----+-----------+
| 2 | shop2 |
+----+-----------+
type table
+----+----------+
| id | variable |
+----+----------+
| 1 | lemon |
+----+----------+
| 2 | potato |
+----+----------+
Date table
+----+------------+
| id | variable |
+----+------------+
| 1 | 2014-10-11 |
+----+------------+
| 2 | 2014-12-11 |
+----+------------+
price table
+----+------------+
| id | variable |
+----+------------+
| 1 | 5000 |
+----+------------+
| 2 | 2000 |
+----+------------+
| 3 | 4000 |
+----+------------+
| 4 | 3000 |
+----+------------+
And what we really need in browser view:
Shop1:
+--------+------------+------------+
| | 2014-10-11 | 2014-12-11 |
+--------+------------+------------+
| lemon | 5000 | 3000 |
+--------+------------+------------+
| potato | 2000 | 4000 |
+--------+------------+------------+
Price is a variable and could be changed like an other variables (dates, type), columns of dates or types could be much more - (max - 5)
This table looks like Excel. But the price must depend on other variables, because other objects could use the same id of price.

First loop Through type table and get the ID
select * from type
Then Loop through ID's as $id
Then In loop you need to query each table for each required value.for example
select variable from price where ID = $id
select variable from date where ID = $id

Related

Update multiple rows with different keys in MySQL

I have this table
inventory
id | name | location | quantity
1 | test | loc1 | 0
2 | test | loc2 | 0
3 | test2 | loc1 | 0
4 | test2 | loc2 | 0
I want to update
test loc 1 with quantity 50
and
test2 loc2 with quantity 100
how do I it?
I have tried using INSERT ON DUPLICATE KEY UPDATE but it doesn't work it just creates new rows
here's the guide I used ITS ON #3
I'm using javascript (nodejs)

Solution for non numeric dynamic input field names

I have students, student_subject, subjects and results tables.
Students Table
| id | name |
|----|-------|
| 1 | John |
| 2 | Sara |
| 3 | Smith |
Subjects Table
| id | name |
|----|-------------|
| 1 | Science |
| 2 | Mathematics |
| 3 | English |
Student_subject Table
| id | student_id | subject_id |
|----|------------|------------|
| 1 | 1 | 1 |
| 2 | 1 | 2 |
| 3 | 2 | 1 |
| 4 | 3 | 1 |
Results Table
| id | student_subject_id | result |
|----|--------------------|--------|
| 1 | 1 | 45 |
| 2 | 2 | 25 |
| 3 | 3 | 65 |
| 4 | 4 | 45 |
There are separate forms to insert students (with selecting subjects), subjects and results. I got a problem creating the form to add results for a student.
The form consists of form inputs listing down all the subjects of the student to enter results. For a specific student, the form to insert results may look like this(after looping the students subjects). The name attribute contains the Student_subject table id value. I add the name to this value because In the database I need to have reference for the student_subject table in the database.
<form>
<input type="text" class="form-control" name="1" required>
<input type="text" class="form-control" name="2" required>
</form>
I want to know this approach is correct or wrong to add results to students?
If not what are the changes I have to do in database and forms.

How to calculate column in table with search on javascript

I have Table :
----------------
| Name | Price |
----------------
| A | 1,200 |
| B | 500 |
| C | 3,000 |
----------------
| sum 4,700|
----------------
If I search " A " I get Table as :
----------------
| Name | Price |
----------------
| A | 1,200 |
----------------
| sum 1,200 |
----------------
How to calculate column with search table and sum change.

Binding Model.ID to Checkbox list and post Model.X, Model.Y, etc. properties to Controller

In an MVC application I joined multiple tables and returned it from Controller to View as shown below:
| EmployeeID | ControlID | DoorAddress | DoorID | DoorName |
------------------------------------------------------------
| 921 | 1 | 1 | 101 | Door 1 |
| 921 | 1 | 2 | 102 | Door 2 |
| 921 | 1 | 3 | 103 | Door 3 |
| 921 | 1 | 4 | 104 | Door 4 |
------------------------------------------------------------
Controller:
public ActionResult Edit(int? id)
{
// Create and execute raw SQL query.
string query = "SELECT a.EmployeeID, a.ControlID, a.DoorAddress, t.DoorID, t.DoorName FROM TEmpAccess AS a " +
"INNER JOIN TDoor AS t ON a.ControlID = t.ControlID and a.DoorAddress = t.DoorAddress where EmployeeID = " + id.ToString();
IEnumerable<EmpAccessViewModel> data = db.Database.SqlQuery<EmpAccessViewModel>(query);
return View(data.ToList());
}
I want to bind DoorName values (Door 1, Door 2, Door 3, Door 4) to a checkbox list and let the user to select them. After that, I want to pass corresponding EmployeeID, ControlID, DoorAddress, DoorID values of the the selected door to the Controller. For example if the user selects Door 1 and Door 3, then I will pass these values below to the Controller:
| EmployeeID | ControlID | DoorAddress | DoorID |
-------------------------------------------------
| 921 | 1 | 1 | 101 |
| 921 | 1 | 3 | 103 |
-------------------------------------------------
By using razor syntax or javascript in the view, how can I do this? Thanks in advance.
If you want a checkbox at the beginning of the Table in the view which is to be passed to the controller and each row is uniquely identified by the DoorID you could try something like this.
in View
<table>
#foreach (var item in Model)
{
<tr>
<td><input type="checkbox" value="#item.DoorID" name="doorid" /></td>
<td>#item.EmployeeID</td>
<td>#item.ControlID</td>
<td>#item.DoorName</td>
</tr>
}
</table>
In controller
public void ControllerName(int[] doorid)
{
foreach(var item in doorid)
//do something
}

preserve spaces in string java, javascript

I am sending data from java code to browser via http request.
data is something like this.
JAVA CODE OUTPUT
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | | | 3 (100)| |
| 1 | FOR UPDATE | | | | | |
| 2 | BUFFER SORT | | | | | |
| 3 | TABLE ACCESS FULL| DD | 4 | 160 | 3 (0)| 00:00:01 |
But when I display it in browser it looks very bad.
Basically I have array of string which I am displaying in browser by using ng-repeat.
when I display it in java code it looks fine, but in browser not so good.
I did tried preserve white spaces but it did not help.
All i need to do is preserve all spaces in string.
{
white-space: pre;
}
Any idea help?
BROWSER OUTPUT.
The easiest way is to wrap it in pre tags, but the best way is to use HTML table cells.
<pre>
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | | | 3 (100)| |
| 1 | FOR UPDATE | | | | | |
| 2 | BUFFER SORT | | | | | |
| 3 | TABLE ACCESS FULL| DD | 4 | 160 | 3 (0)| 00:00:01 |
</pre>
You need to use a monospace font (so that every letter has the same width).
You can do this using css:
{
font-family: "Courier New", Courier, monospace;
}

Categories