SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jul 2000
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have a music database set up that stores music information along with ranks for the "top 20" songs. Currently I change the ranks using a form that lists all of the songs in the db and has a dropdown beside each song to select the rank and a change button beside each rank. This button changes the rank based on the ID of the song.

    Ideally what I would like to do is set it up so that you can go through and rank all of the songs at the same time and just press a change all button. But I am not sure how to go about passing the necessary information to an appropriate mysql querry....

    Any suggestions would be greatly appreciated!

  2. #2
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In your form, use an array of selects. Don't use index numbers in the HTML. That is, for each select use the array name. Also, for each select, I would have a hidden field that held the id (primary key) of the song in the database.

    <select name="songRanks[]">
    <option>1</option>
    etc ...
    </select>
    <input type="hidden" name="ids[]" value="1234">

    This way the whole array will be posted when the user hits the submit button for the form.

    Now you can loop through the arrays in synch when you are processing the form...
    Code:
    // assume you already have a database connection
    $count = sizeof($songRanks);
    for ( $i = 0; $i < $count; $i++ ) {
           myslq_query( "UPDATE tableName
                                     SET rank = songRanks[$i]
                                     WHERE id = ids[$i]");
     }
    Is this the sort of advice you were after?
    Last edited by freakysid; Apr 2, 2001 at 19:22.

  3. #3
    SitePoint Member
    Join Date
    Jul 2000
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That is exactly what I was looking for! Thank you very much!

  4. #4
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey I just corrected 2 really silly mistakes in my code. cmystikal messaged me saying it didn't work. No one picked these up (I have corrected them).

    I relly on other Siteponters (usually Freddydoesphp) to correct my dodgy code -


Bookmarks

Posting Permissions

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