Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I am attempting to create a script or figure out a formula that will allow me to do the following.
I am a teacher and often have student use Google Forms for quizzes and different surveys. When grading it I normally split their email. Occasionally some students will have a number after their last name.
firstname.lastname#stu.county.stateschools.us
I would like to take their e-mail and convert it to the following format.
lastname, firstname
This would allow me to sort easily and put into gradebook much faster.
The current best route I know of to do this is to split via . , # then join the data I want.
This takes multiple different columns to complete my task that could very easily overwrite their data. I want this to all take place in one column and get rid of the extra information I do not need.
There are multiple ways to do that. I would probably start with the indexOf() "#"
slice() the string to get the "firstname.lastname"
Next, split() the string to separate the firstname and lastname
Now reverse() the order of ["firstname", "lastname"]
Finally, join() them back together
var email = "firstname.lastname#stu.county.stateschools.us";
var index = email.indexOf('#');
var name = email.slice(0, index).split('.').reverse().join(', ');
// Logs "The student name is: lastname, firstname"
Logger.log("The student name is: %s", name);
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I plan on having a massive JSON, ~20MB, and I am creating a React Native App using the JSON. I want to have the app:
Download only the changes to the JSON.
or at least
Download only if changes have been made (which will be less than once a month).
If there is something better than Firebase I would be fine switching over to that.
I had the same issue, a huge JSON object which change once a week. the way that I solved this issue is as following
lets say that we have an object O ~20MB
I created in my firebase db the object data = {raw: O, update: Date()}
on the client side I checked /data/update and compare it to the user localStorage. if it changed I replaced the user`s localstorage object, otherwise skipped.
In this way you dont need to download the whole O only to fetch the date object
it looks like
const {update, raw} = localStorage.fetch('/data')
const last_update = firebase.fetch('/data/update')
if(update === last_update){return raw}
const new_raw = firebase.fetch('/data/raw')
localStorage.save('/data', {update: last_update, raw: new_raw})
return new_raw
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I'm extracting data from a MySQL database creating a CSV file with two columns: ID and Text. I would like to know an easy way (SQL, text editor or R solutions) to create a text file for each row containing the second column (text format) with the ID from the first column as the name of the text file. Any ideas? Thanks in advance.
In R I would do the following:
for(i in 1:nrow(df)){
write.table(df$Text[i],
file = paste0(df$ID[i], ".txt"),
col.names = F, row.names = F)
}
list.files()
# [1] "1.txt" "10.txt" "11.txt" "12.txt" "13.txt" "14.txt" "15.txt" "16.txt"
# ----
# "76.txt" "77.txt" "78.txt" "79.txt" "8.txt" "80.txt" "81.txt" "82.txt" "9.txt"
I did a loop based on what you said #Ken S. but it's 90,000 rows that need to be converted into individual files. The R loop is only able to produce 5 per minute, which means it would take several days to finish. Thanks though!
for (i in 1:91020) {number=descriptions[i,1]
text=descriptions[i,2]
print(text)
write.table(text,file=paste0(number, ".txt"))}
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
Since I got several "projects" that should contain many questions each, I have a question-page where I fill a videolink, four answers and four drow-down lists where the user is able to set points for every answer.
However, in the database I have two tables.
When I fill and execute my question page I have made so every answer gets an id. In the table "answer_det", Pid, Aid, answer and points is being set. This is how it looks like:
The "question" table when I insert the first question for the first project(Pid=1) :
What I want to do now is to also set the qid(question-id). I'm not sure how to do it, but I think that I should have a code that checks the maximum qid of the pid and add 1 to it so every new question for the same project get a new qid. If the pid isn't in the table, then the qid should get the value "1".
So if you look at the first picture, the qid should be 1 on every showed row since all the four answers belongs to the same question, which is the first one for the project with pid=1. So if I would like to add a question to the same project, it should look the same but with the qid=2 and so on. If I then add a new(first) question for the project 2, the qid should begin on 1 and so on. Then, if i would like to add a new question again for the first project, the code should check that the maximum qid is 2 where pid is 1, and then insert a new question with answers but with qid=3.
It should work the same way on the table "question", which you see on the second picture. When the first question is created, I want the first question for the first project(the one with pid=1) to also have qid=1 and the link that I filled. The second question for the project with pid=1 should then get qid=2. If i add a first question for a new project, it should then be pid=2 and qid=1.
This is the code that I have now, and nothing of it inserts anything in the qid in neither of the two tables.
I suppose you have a predefined set of projects:
Project 1> Science
Project 2> Maths
Project 3> History.....and so on.
I suggest you create a separate table for projects that would have projectID and projectName columns.
Now in your question-page, have these projects in a dropdown(select option) format with projectID as the option value and projectName as the dropdown select name.
Now you have a select option for project name, an input field for question_link and other select options for answers and their weight-age. Now when you insert this form (this question) try coding the following logic (I will just try to write in pseudo-code manner)
//first check if this project already has questions in the question table.
So do something like
SELECT* FROM question WHERE pid = $post['projectID'] ORDER BY qid DESC
// or you could do SELECT TOP 1
// CASE1: if this project never had any questions, the select would return null.
//Hence this is a first question for this project. Then simply write an insert query that
//would insert $post['projectID'] to pid and 1 in qid (since this is the first question).
//Also, insert a series of rows in the answer_det table that will have $post['projectID']
//to pid and 1 for qid and the answer and points as submitted.
// CASE2: if this project already has 1 or more questions, your select query from above
//will return some rows and if you pick $row[0]['qid'], this would be the highest number
//value for question (qid) as we selected using ORDER BY qid DESC. Now, simply do inserts
//in both the tables like you would do as above but this time, in the qid field in both
//the tables, instead of inserting 1, you would insert qid => $row[0]['qid'] + 1.
//You wouldn't need to know what the qid was, all you need is to get the last qid and add
//1 to it.
//Also, you can create a separate page to add the projectName as you feel to add new
//projects and insert this into the project_table and this will begin to show up in the
//select options when you are adding new questions.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Can anyone help by describing this php mysql command please:-
SELECT itm.*,mem.username as username,cpn.*
FROM aw_rdw_items itm,members mem,aw_rdw_items_coupons cpn
WHERE itm.item_id=cpn.item_id
and item_special_type != 'g'
and itm.item_id=cpn.item_id
and itm.memberid=mem.memberid
and item like('%".addslashes($_REQUEST["item_name"])."%')
$prs1 $prs2 $greenget $subsql
ORDER BY Display_Order,itm.item_id ASC
SELECT
itm.*, // all columns of table itm
mem.username as username, // column username and assign the values to a variable called username
cpn.* // columns of table con
FROM aw_rdw_items itm, members mem, aw_rdw_items_coupons, cpn // tables where execute the research
WHERE itm.item_id=cpn.item_id // various conditions
and item_special_type != 'g'
and itm.item_id=cpn.item_id
and itm.memberid=mem.memberid
and item like('%".addslashes($_REQUEST["item_name"])."%') // item must contain the specified variable
$prs1 $prs2 $greenget $subsql // some php variables
ORDER BY Display_Order, itm.item_id ASC // order by Dispay_Order and itm.item_id in ascendant mode
Return all records who item_special_type is different from "g" and item contains value from item_name request value.
Where clause has another conditions that contained at $prs1, $prs2, $greenget and $subsql variables.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
tbl_messages:
m_from----m_to----m_message----m_date--------m_time1000------1001----hello-------------2013-02-01----12:11:111001------1000-----hi----------------2013-02-01----13:10:111000------1001-----how r u?-------2013-02-01----16:19:111001------1000-----fine------------(2013-01-26)---12:11:111002------1003-----ur age?---------2013-03-10--13:14:111003------1002-----25----------------2013-03-11--13:36:151002------1000-----ur name?-------2013-02-04--13:52:441002------1000-----rihanna----------2013-05-15--13:11:541000------1002-----im there---------2013-02-01--13:34:111000------1003-----im here----------2013-02-01--13:04:00
For example user(1000)=Michael wants to see his messages.
Michael should only see users that send or receive message.
user(1000)=michael===messege send or receive====> user(1001)
user(1000)=michael===messege send or receive====> user(1002)
user(1000)=michael===messege send or receive====> user(1003)
I want SQL code that only users shows that Michael has a message exchange with them. The result be with last message (send or receive) ORDER BY (first) m_date (second) m_time
example: (this result is for user(1000))
user(1001)=david----------------------------------------------------time=16:19:11send:slice of message(how r...)-----------------------------------date=2013-02-01user(1002)=jenifer----------------------------------------------------time=13:11:54received:slice of message(rihanna...)----------------------------date=2013-05-15user(1002)=tom--------------------------------------------------------time=13:04:00send:slice of message(im here...)----------------------------------date=2013-02-01
Supposing a table tbl_users with fields u_id and u_name.
Something along the lines of
(SELECT m_from, u_name, u_time, 'sent', m_message, m_date
FROM tbl_messsages inner join tbl_users on tbl_messages.m_from = tbl_users.u_id)
UNION
(SELECT m_to, u_name, u_time, 'received', m_message, m_date
FROM tbl_messsages inner join tbl_users on tbl_messages.m_to = tbl_users.u_id)
ORDER BY m_date, m_time;
Now, MySQL can do fancy things for formatting, but if I read your examples correctly, it can't put them like that, most likely, and you don't want to. A database (MySQL and others) is not made to do complex format transformation, but to store and retrieve information. The formatting can be done outside in another language.