PDA

View Full Version : Sorting on 2 varibles, is it possible?



mdcloud
04-25-2007, 03:18 PM
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
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>';
}


?>

mdcloud
04-26-2007, 06:03 PM
any one know how i would take the output of the first while and add a second to just those results?

brent

Twey
04-26-2007, 06:52 PM
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.
<td>FName&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td> Ouch!
$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:
$date = mysql_real_escape_string($_POST['date']);

mdcloud
04-26-2007, 09:55 PM
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.

mdcloud
04-30-2007, 02:23 PM
can no one help on this one?

please?

boogyman
04-30-2007, 02:29 PM
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