View Full Version : Saving a query result

10-15-2004, 12:01 PM
I have a list of words taken from mysql. Now, I'd like to give the user the option to "save" the list, where it emails them the list as well as updates in in the database.

I've tried a million different ways and they all do what I don't want them to. Let me explain:

The words come up like so:

69654) Neuroanatomy
26444) Cauline
76930) Phoneticism
68923) Nailless
23968) Buchu
82004) Puggy
72758) Outcharm
16904) Aperient
14058) Adhere
29330) Coasting
Total: 39 points
Minimum Length <input field here>
Maximum Length <input field here>
# of Words: <input field here>
Save List as Today's

"Save List as Today's" is a link: wordlist.php?do=savelist. When that is clicked, I'd like to update the DB, email, all that without the list refreshing. Here's my code:

$total = 0;

$getWords = mysql_query("SELECT word, id, LENGTH(word) AS len FROM all_words WHERE LENGTH(word) > $min AND LENGTH(word) < $max ORDER BY RAND() LIMIT 0, $limit");

while($r = mysql_fetch_assoc($getWords)){
$today[] = $r['word'];

$total += $r['len'];
//display code removed... just echoing <tr>, <td> etc...
if(isset($_GET['do']) && $_GET['do'] == 'savelist'){
foreach($today as $todo){
$words[] = $todo; //not holding for the if statement above
//something.. im stuck

But the list always changes/refreshes. I just need it to store the current list in the session. Hope this makes sense :)

I've tried sessions, and it's too much trouble. I would think it would be easy, but it's proving otherwise.

10-15-2004, 07:35 PM
What do you mean by "save the list"? Download it or save it in a db? What are you updating? Do the words get deleted from the db (are temporary)? Sessions hold only temporary data.
You could create a TABLE my_saved_words and store the id's of words that are in that list in it.

10-15-2004, 10:57 PM
By "saving" I mean I'd like to store the current list of words that is being displayed into a table in mysql. There are 2 buttons that the user can click... one a submit button called "Get New List" which just refreshes the page, thus retrieving a new list. The other a "Save List" which I'd like to store the current list (the one being displayed) into a DB.

The problem I am running into is I can't seem to get the list to not refresh (and thus retrieve a new list) when they choose "Save List".

The way I thought it would work is checking the length of the array $words. As you can see, when the page is executed, a mysql_query is called, and then those words are displayed. I removed all the display code, but you can see where it was (commented). Now, as the while loop does it's thing, it also adds the word to an array called $today:

while($r = mysql_fetch_assoc($getWords)){
$today[] = $r['word'];

So then that stores the words retrieved from the database into an array.

When they like the list, they'll hit the "Save List" link. That link's href looks like wordlist.php?do=savelist. I've tried having that link be a submit button instead, and just do different actions based on the name of the submit button, but I'm at a total loss.

10-19-2004, 10:56 PM