-1

I learned JavasSript, HMTL, CSS, and jQuery on Codecademy.com and began building a website that provides users with a To Do list that they can edit and sort. I coded it in Sublime Text and just have it on my computer currently.

My question is, what is the best and easiest way to store individual users' To Do lists (and some other information) so that they can login and come right back to that same list when they return to the site?

I really don't know anything at all about how to go about doing this so using as much plain English as possible in your response would be greatly appreciated.

I started taking a Codecademy course on Apigee's API, which seems to allow you to do what I am looking for but the course is not written very well and seems to have some bugs in it. I'm also not sure if using Apigee is the best way to go about doing this.

Ian
  • 50,146
  • 13
  • 101
  • 111
Jackmc1047
  • 391
  • 2
  • 5
  • 12
  • 1
    "Best" and "Easiest" are very subjective, and therefore make this not a great question for SO. Among other things, we don't know what you know already, so what is easiest depends a lot on your background. Generally speaking, storing user specific data means you will need to have some sort of server side processing and database. There are many tutorials and books out there on doing this sort of thing on different platforms - Ruby on Rails, PHP, ASP.NET, etc... – Jason May 31 '13 at 21:25
  • 1
    `cookies` or `local storage` would store the list to their machine, and can be done in JS without additional serverside support. Have you tried either of those? – Jason Nichols May 31 '13 at 21:29
  • Jason, I have not. Can you direct me to a resource where I can learn how to do this? Also, why do certain websites choose not to do this? – Jackmc1047 May 31 '13 at 21:32

2 Answers2

1

Each user would have a row entry in your users table. You could have a very large text field (say, called ToDoList) and store each list entry as a string, with strings separated by a character of your choosing.

For example:

"Go to the store|Take dog to vet|Buy Dad a birthday card|Mail Dad's card"

When the user logs in, you would read that user's entry from the database, reading in that field.

$u = mysql_result(mysql_query("SELECT * FROM `users` WHERE `user_id` = '$user_id'), 0);
$toDoStr = $u['ToDoList'];

You would then explode the string back into individual array elements, using explode(). $arrToDo = explode("|", $toDoStr);

When the user is ready again to save his revised ToDo list, you could loop through the HTML fields and get all the values, and re-create this ToDoList string. Note that (upon saving to database) you would need to check each To Do List item for your separation character (in this example, the | char) and replace with a different character.

cssyphus
  • 37,875
  • 18
  • 96
  • 111
  • Thanks for your answer. My To Do list site uses some other features as well that increases the complexity, such as a timer and multiple sortable and draggable lists so it becomes a little complex (although obviously not impossible) to grab just the unique information for each user and then programmatically recreate the HTML page when the user signs in. Is there a reason that I would not just grab all of the HTML between the body tag for each user in one giant string and store it, and then use all of that HTML to recreate the page just as they left it each time? – Jackmc1047 May 31 '13 at 21:44
  • Okay, I can see from your response above that you didn't need my example code above, so forgive the over-assist. You could try doing that, I suppose, using AJAX to POST the data to a php file that saves it into your database..? I've never tried anything like that, though, so I can't really say if it would work. Give it a try with a simplified example and see what works. – cssyphus May 31 '13 at 21:58
0

I would suggest a simple SQL like database to store everything, with a table that holds an entry per user. SQLite ( http://www.sqlite.org/ ) would be a great database to use for your idea.

A library I have used previously can be found here: https://github.com/jhubert/javascript-sqlite

CJ Ratliff
  • 333
  • 1
  • 2
  • 11