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

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


// 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">
<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>
// Show data for each user
while($u = mysql_fetch_array($users)) {
echo '
<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>
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>
<input type="submit" name="search" value="Search" />
</form><br><br><br><a href="bih.html">&lt;&lt;Back</a>';


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?


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']);

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.

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


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