I have a table which was the following:
ID Pttributes Pvalue
1 Name Jason
2 Age 14
3 Address 12 Test Road
A linq query has been produced which selects each individual value by their ID
from p in db.people
where p.ptribbutes.contain(string) || p.value.contains(string)
select p.tribbutes , p.value ,
Now this is where it gets tricky , when it is outputted towards JSON in MVC View , it outputted as separate rows in individual div elements (which has been incremented) where the code is written in javascript as
item.ptribbutes + item.pvalue
Output value
Div 1
-------
Name - Jason
Div 2
--------
Age - 14
Div 3
---------
Address - 12 Test Road
How do I get it so one div can contain all these rows rather than being in separate div elements? (or possibly recognize the name , age and address as columns)?
1) Understand what is getting returned as JSON data. It is an array of objects.
2) How do you want it to display the JSON data in UI? I understand that as an single div for each array element. So what do you need to do is to loop thru the JSON data and either bind/emit the values in UI element inside (div) whichever way you prefer to do it. Take a look at the answer for the question at loop through JSON result with jQuery
Hope this helps. Happy Coding!
Related
I’ve been trying to figure out how to write a script which will take the value from one cell and append it to the end of a string of numbers in another cell of that same row. The newly appended number needs to be separated by a comma from the previously appended value, and the whole string needs to be wrapped between brackets. EX. [2,3,3,4.5,2.5,2.1,1.3,0.4]. The script will need to loop through all of the rows containing data on a named sheet beginning with the third row.
The above image is obviously just an example containing only two rows of data. The actual spreadsheet will contain well over a thousand rows, so the operation must be done programmatically and will run weekly using a timed trigger.
To be as specific as I can, what I need help with is to first know if something like the appending is even possible in Google App Scripts. I've spent hours searching and I can't seem to find a way to append a new value (ex. cell A3) to the current string (ex. cell B3) without overwriting it completely.
In full disclosure; I'm a middle school teacher trying to put something together for my school.
To be as specific as I can, what I need help with is to first know if something like the appending is even possible in Google App Scripts.
Seeing the expected result, it's inserting rather than appending, as the string should be added before the last character (]). Anyway, yes, this is possible by using JavaScript string handling methods.
Use getValue() to the get the cell values, both the Current GPA and the GPA History.
One way is to use replace
Example using pure JavaScript:
var currentGPA = 3.5
var gpaHistory = '[2,3.1,2.4]';
gpaHistory = gpaHistory.replace(']',','+currentGPA+']');
console.info(gpaHistory)
Once you get the modified gpaHistory, use setValue(gpaHistory) to add this value to the spreadsheet.
Right now I am coding in PHP & HTML
I need to make a selection from the checkbox group
and it goes like this:
The value in the dropdown menu is retrieved from the value stored in the database in table subject. So the checkbox options will appears as (for example) Mathematics, Algebra, Calculus, English, Linguistic etc. -- I have no problem with displaying this one.
Table subject
subject_id subject_name
========== ============
1 Mathematics
2 Algebra
3 Calculus
4 English
5 Linguistic
So after that, a student can choose their subject and it will be stored in another table named student_subject where it stores the student_id and the subject_id (to store what subjects did a student chose)
Example:
table student_subject
student_id subject_id
========== ===========
1 1
1 2
1 3
2 1
2 3
Now, the student comes again to add another subject to his profile. The same checkbox option will be displayed as mentioned earlier in (1) but I would love to disabled/remove/not display the already selected option from being selectable again to avoid redundancy.
I really have no idea on how to create this function. I know there are a lot of experienced programmers and developera here so I wish you could show me the right way. Your guidance is highly appreciated.
You should not remove/disabled/not display the existing subjects.
First, you should check for existing rows for student_subject table and render it in HTML checkbox as selected.
Second, while student makes changes for subject selection in edit mode, check with the database rows with student and subject ids in a loop.
If submitted subject id for the student is not available in the database, insert that value to the table.
If submitted subject id for the student is available in the database, do nothing with it.
Check for the removed subject from submitted values with the database, and delete from the database.
If you want to disable existing subjects, use readonly to the checkbox if the subject is assigned to the student.
This is just an idea:
On your #2 where a table will store student_id and subject_id, I think it's best that whenever you store value to subject_id- you just serialize the value by storing it on an php array in that way you can iterate the whole array if the field was checked or not.
Json_encode is also good since it will be a string and same as serialize
Example:
Student_id Subject_ID
999-0518 a:{this is the serialize value };
Then when you query the result it will be serialize, then use unserialize function and do a loop to iterate the results, same goes when you json_encode; just perform json_decode() function and perform loop.
You can use a query which only picks up subjects which ID isn't in student_subject.
It would look something like:
SELECT * FROM `subject`
WHERE `subject_id` NOT IN (
SELECT `subject_id` FROM `student_subject` WHERE `student_id` = '1'
)
(you can ommit the inner where clause if you don't want this to be user specific)
and then build the <select> element based on the array returned from it.
I am struggling to come up with a query for sqlite table to UPDATE OR INSERT at rowid. The problem I have is that I have a database where it relies on the rowid but when populating the table there may not be enough rows. So the table may look like this:
rowID data1 data2 data3
------ ------ ----- ------
0 18 1543
1 5
2 35 918
And for my query I want to be able to insert data2 = 453 at rowID = 16 for example. Also just to specify I do not have a column of rowID.
I am thinking that the only way possible would be to insert empty rows from rowID 3 -> 15 before inserting the 16th row. It does not matter for me if rows are empty as they will eventually be populated. I will not be working with more than 50 rows or more than 8 columns so it is a reasonably small table. Anyone know a way forward for me to work?
Also additional thing to note, I am using the query on Titanium, so the programming language is JavaScript.
The documentation says:
The rowid value can be accessed using one of the special case-independent names "rowid", "oid", or "rowid" in place of a column name.
[...]
An INSERT statement may provide a value to use as the rowid for each row inserted.
So just specify the values you want:
INSERT INTO MyTable(rowid, data2) VALUES(16, 453)
I have a project that consist of a function that generate a table based on some filter. Then, I found a problem that when some combination of some filter are return nothing so, when it rendered in browser as a table is less than number of combination.
To achieve it, I want to give "-" mark to the loss record that not saved in the table.
My first approach is check one-by-one the array with the filter and if the condition is match to 'loss rows', it will push array untill all missing record in result is filled with '-'. But, it'll dealing with time because, the last must be sorted again and then to be constructed into the wanted table.
Sample schema of main table "A":
amount_of_product, id_product, id_people, id_place.
The primary key columns are:
id_product, id_people, id_place.
The content of the main table is:
23456, book-a, 1, aa
5678, book-b, 1, cc
2587, book-b, 1, aa
The source query will be something like:
select * from A
where
id_product in ('book-a', 'book-b')
and id_people in ('1') and id_place in ('aa', 'bb', 'cc')
order by id_product, id_place
Then, we want to show in a table view (html) all combinations of all selected filters. 6 rows should be rendered, with empty cells shown as "-".
Sample result table:
Can I do it efficiently or are there any solution to this?
Thanks in advance.
Thanks for some advice above.
I've try to use crosstab function in postgresql to produce the pivot table but I can't produce for more complex table.
So, I use another approach to retrieve all datas based on combination row-coloumn gradually (example query from id_place 'aa', id_people '1', id-product 'aa' etc) and contruct each table head row and coloumn then contruct the data.
Regard
I am returning a query object from Coldfusion as a JSON string which I then parse into JSON in Javascript. It has a bit of a strange format when I finally log it though.
I am faced with two problems. First, I do not know how to access the lowest element (i.e Arthur Weasley) as I cannot use a number in my selector (response.DATA[0].0 doesn't work because the lowest field name is a number). Second, is there any way to assign the values in the columns section to the fields that are numbered 1, 2 and 3?
What I'm really asking is how do I select my lowest level of data? If that can't be done because of the numbers for field names, how do I change the names to something more fitting?
My data logged:
First entry of first entry of DATA = response.DATA[0][0]
So
name = reponse.DATA[0][0];
trainsThing = response.DATA[0][1];