SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist jazztie's Avatar
    Join Date
    Mar 2001
    Location
    the Netherlands
    Posts
    519
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Prioritizing a list

    I have the following problem:

    I have a database-table with information about a TO-DO list.

    The table consist of:
    TDID
    TDDescript (description of the todo)
    TDDateIN (Date it was added)
    TDDateOUT (Date it was finished)
    TDPriority (Priority of the Item)
    TDRequestor (The one that requested the item)

    Now, to create a list is farely easy. What I want to do, however, is to prioritize the list.

    I could, for instance, put a number in the TDPriority row. But, I also want to change priority of the items I have. Say I have three items:
    1. (001)(To do 1)(12-12-2000)()(1)(Jack)
    2. (002)(To do 2)(12-12-2000)()(2)(Jack)
    3. (003)(To do 2)(12-12-2000)()(3)(Jack)

    And I want to move item 003 up the list. How do I go about this???

    Any help is appreciated!!
    Jazz

  2. #2
    SitePoint Evangelist jazztie's Avatar
    Join Date
    Mar 2001
    Location
    the Netherlands
    Posts
    519
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just to be sure...

    The query itself is not the problem:

    $Query = mysql_query("SELECT * FROM TODO SORT BY TDPriority");

    The problem I have is, with changing the priority

  3. #3
    SitePoint Addict zoordaan's Avatar
    Join Date
    Feb 2001
    Location
    NYC/Texas
    Posts
    348
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can use the order by clause to organize by tdpriority of the to-do item.

    order by TDPriority desc This will organize from the higest priority to lowest.

  4. #4
    SitePoint Evangelist jazztie's Avatar
    Join Date
    Mar 2001
    Location
    the Netherlands
    Posts
    519
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that's not really my question...

    I'm wondering about how I'm going to change all the items in the table, when shifting one of the items to a higher priority!

  5. #5
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think thats gonna get a bit tricky. The first thing that comes into mind is to take all records and print them with a dropdown list next to each one with each element of the dropdown list being a number between 1 and the number of elements in the table. Set each drop down to the current priority for each record, and the name of the drop down being an array with the key of the id. Now you can repopulate the table. If I thoroughly confused you, then join the club, because I am confused too. But here is my attempt and it seems to work fine. It just might get a little tedious with more than say 10 items to prioritize.

    PHP Code:
    <?
    $db 
    mysql_connect("localhost""root""");
    mysql_select_db("test");

        
    //Check for form submission
        
    if(count($priorities)) {
            foreach(
    $priorities as $key => $val) {
                
    $r mysql_query("UPDATE test set priority = '$val' WHERE id = '$key'") or die(mysql_error());
                }    
            }

    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

    <html>
    <head>
        <title>Untitled</title>
    </head>

    <body>
    <form action="<?=$PHP_SELF?>" method="POST">
    <?
    $result 
    mysql_query("SELECT * from test order by name");
    while(
    $row mysql_fetch_array($result)) {
        
    extract($row);
        
    ?>
        <?=$name?> 
        <select name="priorities[<?=$id?>]">
        <?
            
    for($i=1;$i<=mysql_num_rows($result);$i++) {
            
            
    ?>
                <option value="<?=$i?>"<?=($priority == $i) ? ' selected' ''?>><?=$i?></option>
            <?
            
    }
        
    ?>
        </select><br><br>
        <?
        
    }

    ?>
    <br>
    <input type="submit" name="submit" value="update">
    </form>
    </body>
    </html>

    Of course you'll need to change the db names and field names to reflect your setup.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.


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
  •