Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Feb 2004
    Location
    California
    Posts
    96
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Saving a query result

    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:

    Code:
    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:
    PHP Code:
    $total 0;

    if(empty(
    $words)){
        
    $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.

  • #2
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    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.

  • #3
    New Coder
    Join Date
    Feb 2004
    Location
    California
    Posts
    96
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:

    PHP Code:
    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.

  • #4
    New Coder
    Join Date
    Feb 2004
    Location
    California
    Posts
    96
    Thanks
    0
    Thanked 0 Times in 0 Posts


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •