Results 1 to 6 of 6

Thread: Sorting on 2 varibles, is it possible?

  1. #1
    Join Date
    Mar 2007
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Sorting on 2 varibles, is it possible?

    hello everyone, thanks so much for your continued help. here is what i got. i have a database of people signing up for classes. i need to be able to sort first on date and then on printed so i can give the registration lady a way to see who she has dealt with already. here is the code i have so far that just sorts by date. i have no idea where to put the second argument. thanks for any help you can give

    PHP Code:
    <?php 
        
    require('link.php'); 
         
    // If search is active 
    if ($_POST['search']) { 
        
    $date $_POST['date']; 
        
    $count 0;
         
        
    // Get results from database 
        
    $users mysql_query("SELECT * FROM `form` WHERE Date = '$date' ORDER BY RegID DESC") or die ('Error Getting Users! \n<br />\n' .mysql_error()); 
        
    $chk mysql_num_rows($users); 
         
            
    // If no users found 
            
    if ($chk 1) { 
                echo 
    'There are no users registered on the date: <b>'.$date.'</b> 
                    <br /> 
                <a href="bih.html">&lt;&lt;Back</a>'

            } 
             
            
    // If there are users 
            
    else { 
             
                
    // Set header to download users 

     
                 
     
                    
    echo 'People attending '.$date.'<br><br>
    <table border="1">
    <tr>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td>FName&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
    <td>LName&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
    <td>EMail&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
    <td width="150">Phone&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
    <td>Address&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
    <td>City&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
    <td>State</td>
    <td>Zip</td>
    <td>OState&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
    <td>Country&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
    <td>DOB</td>
    <td>Occ&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
    <td>Meds&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
    <td>Married</td>
    <td>Accomidation&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
    </tr>'
    ;
                    
    // Show data for each user
                
    while($u mysql_fetch_array($users)) { 
    echo 
    '
    <tr>
    <td><a href="edit.php?RegID='
    .$u['RegID'].'">Edit</a></td>
    <td><a href="delete.php?act=chk_del&RegID='
    .$u['RegID'].'">Delete</a></td>
    <td><a href="view.php?RegID='
    .$u['RegID'].'">View</a></td>
    <td><a href="print.php?RegID='
    .$u['RegID'].'">Print</a></td>
    <td>'
    .$u['FName'].'</td>
    <td>'
    .$u['LName'].'</td>
    <td>'
    .$u['EMail'].'</td>
    <td>'
    .$u['Phone'].'</td>
    <td>'
    .$u['Address'].'</td>
    <td>'
    .$u['City'].'</td>
    <td>'
    .$u['State'].'</td>
    <td>'
    .$u['Zip'].'</td>
    <td>'
    .$u['OState'].'</td>
    <td>'
    .$u['Country'].'</td>
    <td>'
    .$u['DOB'].'</td>
    <td>'
    .$u['Occ'].'</td>
    <td>'
    .$u['Meds'].'</td>
    <td>'
    .$u['Married'].'</td>
    <td>'
    .$u['Accom'].'</td>
    </tr>'
    ;
    $count++;
    }
    echo 
    '</table> <br><br>Number Of Attendees is '.$count.'<br><br><a href="bih.html">Back</a>'
                } 
                 
                
    // End table 
               
            



    // download on click
    if (!$_POST['search']) { 
        echo 
    ' <center><h2>Download Program Signups.</h2></center><br><br>
        <form method="post" action=""> 
            <b>Date:</b> <select name="date" size="1">
    <option selected value="">Program...</option>
    <option value="For My Life 04/22/07 - 04/28/07">For My Life 04/22/07 - 04/28/07</option>
    <option value="For My Life 04/29/07 - 05/05/07">For My Life 04/29/07 - 05/05/07</option> 
    <option value="For My Life 05/13/07 - 05/19/07">For My Life 05/13/07 - 05/19/07</option> 
    <option value="For My Life 05/20/07 - 05/26/07">For My Life 05/20/07 - 05/26/07</option>
    <option value="For Their Life 05/20/07 - 05/26/07">For Their Life 05/20/07 - 05/26/07</option>
    <option value="For My Life 06/03/07 - 06/09/07">For My Life 06/03/07 - 06/09/07</option>
    <option value="For My Life Childrens 06/03/07 - 06/09/07">For My Life Childrens 06/03/07 - 06/09/07</option>
    <option value="For My Life 06/10/07 - 06/16/07">For My Life 06/10/07 - 06/16/07</option>
    <option value="For Their Life 06/10/07 - 06/16/07">For Their Life 06/10/07 - 06/16/07</option>
    <option value="For My Life 06/24/07 - 06/30/07">For My Life 06/24/07 - 06/30/07</option>
    <option value="For My Life 07/08/07 - 07/14/07">For My Life 07/08/07 - 07/14/07</option>
    <option value="For Their Life 07/08/07 - 07/14/07">For Their Life 07/08/07 - 07/14/07</option>
    <option value="For My Life 07/22/07 - 07/28/07">For My Life 07/22/07 - 07/28/07</option>
    <option value="For My Life 07/29/07 - 08/4/07">For My Life 07/29/07 - 08/4/07</option>
    <option value="For Their Life 07/29/07 - 08/4/07">For Their Life 07/29/07 - 08/4/07</option>
    <option value="For My Life 08/12/07 - 08/18/07">For My Life 08/12/07 - 08/18/07</option>
    <option value="For My Life Childrens 08/12/07 - 08/18/07">For My Life Childrens 08/12/07 - 08/18/07</option>
    <option value="For My Life 08/19/07 - 08/25/07">For My Life 08/19/07 - 08/25/07</option>
    <option value="For Their Life 08/19/07 - 08/25/07">For Their Life 08/19/07 - 08/25/07</option>
    <option value="For My Life 09/02/07 - 09/08/07">For My Life 09/02/07 - 09/08/07</option>
    <option value="For My Life 09/09/07 - 09/15/07">For My Life 09/09/07 - 09/15/07</option>
    <option value="For Their Life 09/09/07 - 09/15/07">For Their Life 09/09/07 - 09/15/07</option>
    <option value="For My Life 09/23/07 - 09/29/07">For My Life 09/23/07 - 09/29/07</option>
    <option value="For My Life 09/30/07 - 10/06/07">For My Life 09/30/07 - 10/06/07</option>
    <option value="For My Life 10/14/07 - 10/20/07">For My Life 10/14/07 - 10/20/07</option>
    <option value="For My Life Childrens 10/14/07 - 10/20/07">For My Life Childrens 10/14/07 - 10/20/07</option>
    <option value="For My Life 10/21/07 - 10/27/07">For My Life 10/21/07 - 10/27/07</option>
    <option value="For Their Life 10/21/07 - 10/27/07">For Their Life 10/21/07 - 10/27/07</option>
    <option value="For My Life 11/04/07 - 11/10/07">For My Life 11/04/07 - 11/10/07</option>
    <option value="For My Life 11/11/07 - 11/17/07">For My Life 11/11/07 - 11/17/07</option>
    <option value="For Their Life 11/11/07 - 11/17/07">For Their Life 11/11/07 - 11/17/07</option>
    <option value="For My Life 11/25/07 - 12/01/07">For My Life 11/25/07 - 12/01/07</option>
    <option value="For My Life 12/02/07 - 12/08/07">For My Life 12/02/07 - 12/08/07</option>
    <option value="For Their Life 12/02/07 - 12/08/07">For Their Life 12/02/07 - 12/08/07</option>
    <option value="For My Life 12/09/07 - 12/15/07">For My Life 12/09/07 - 12/15/07</option>
    </select>
            <input type="submit" name="search" value="Search" /> 
        </form><br><br><br><a href="bih.html">&lt;&lt;Back</a>'




    ?>

  2. #2
    Join Date
    Mar 2007
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    any one know how i would take the output of the first while and add a second to just those results?

    brent

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    SELECT * FROM `form` WHERE Date = '$date' ORDER BY RegID DESC, Date DESC
    ... but I don't see the point, since you're only selecting users with a single date anyway.
    Code:
    <td>FName&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
    Ouch!
    Code:
        $date = $_POST['date'];
    Much, much bigger ouch! By using the raw POST data in a query, you're giving attackers a way to execute any query they want against your database. Instead, escape it:
    Code:
        $date = mysql_real_escape_string($_POST['date']);
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #4
    Join Date
    Mar 2007
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    the point is i want to filter the results i get from the date search.

    what does the escape string do? i am very new to all this, so you will have to forgive my ignorance.

  5. #5
    Join Date
    Mar 2007
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    can no one help on this one?

    please?

  6. #6
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    an escape string is a way of "sanitizing" or cleansing the input as a way to stave off harmful code either by accident or done maliciously in an attempt to gain access to your server... NEVER trust any input a user gives you, and always preform some validation / sanitation on the input, so at the very least it will reject hackers that are "just starting out"... also it is a way to prevent some accident by a user who wasn't trying to be harmful

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
  •