Jump to content


Photo

sort by date


  • Please log in to reply
4 replies to this topic

#1 muddy004

muddy004
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 20 July 2006 - 04:47 PM

Dear Freaks,

I have a very simple php page (that I've inherited) that grabs 3 sets of data from the database using a drop down menu and a go button:

The drop down shows these 3 choices:

Show New Records
Show Processed Orders
Show All Records


What do I have to do to the page below to make the "Show Processed Orders" display the records sorted by date?

Thanks a million!



<?php echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?".">"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Secure Data Retrieval</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<?php
  $dbh = mysql_pconnect('localhost', 'username', 'password') or die('Could not connect with the database');
  mysql_select_db('3pr', $dbh);
  
  //CHECK FOR SET POST_VARS
  foreach($_POST as $Key => $Value) {
    if(preg_match('/^FV_Delete_Me_*./', $Key)) {
	  $Delete_Match .= "$Value," ;
	}
	if(preg_match('/^FV_Process_Me_*./', $Key)) {
	  $Process_Match .= "$Value," ;
    }
  }
  
  //DELETE RECORDS
  if(isset($Delete_Match)) {
    $Delete_Customer = "DELETE
  					    FROM Customer
  					    WHERE c_id in ( ";
    $Delete_Customer_Order = "DELETE
  							  FROM Customer_Order
  							  WHERE co_c_id in ( ";
    $Delete_Customer .= "$Delete_Match 0)";
	$Delete_Customer_Order .= "$Delete_Match 0)";
	mysql_query($Delete_Customer, $dbh);
	mysql_query($Delete_Customer_Order, $dbh);
  }

  //PROCESS RECORDS
  if(isset($Process_Match)) {
    $Process_Customer = "UPDATE Customer
  					      SET c_processed = '1',
						  	  c_card_number = ''
					    WHERE c_id in (";
    $Process_Customer .= "$Process_Match 0)";
	mysql_query($Process_Customer, $dbh);
  }
  
  $Get_Data = "SELECT Customer.c_id,
					  DATE_FORMAT(Customer.c_date_created, '%m/%d/%Y at %h:%m%p') 'c_date_created',
					  Customer.c_processed,
					  Customer.c_first_name,
					  Customer.c_last_name,
					  Customer.c_street_address,
					  Customer.c_city,
					  Customer.c_state,
					  Customer.c_zip,
					  Customer.c_phone,
					  Customer.c_email,
					  Customer.c_card_type,
					  Customer.c_card_number,
					  Customer.c_expiration,
					  Customer.c_item_ordered,
					  Customer_Order.co_id,
					  Customer_Order.co_date_created,
					  Customer_Order.co_date_modified,
					  Customer_Order.co_first_name,
					  Customer_Order.co_last_name,
					  Customer_Order.co_street_address,
					  Customer_Order.co_city,
					  Customer_Order.co_state,
					  Customer_Order.co_zip,
					  Customer_Order.co_phone,
					  Customer_Order.co_email,
					  Customer_Order.co_comments
				 FROM Customer, Customer_Order
				WHERE Customer.c_id = Customer_Order.co_c_id";

  if(!$_POST['FV_Action_Select'] || $_POST['FV_Action_Select'] == 1) {
    $Get_Data .= " AND Customer.c_processed is NULL";
  }
  elseif($_POST['FV_Action_Select'] == 2) {
    $Get_Data .= " AND Customer.c_processed IS NOT NULL";
  }
				
  $Get_Data_Result = mysql_query($Get_Data, $dbh);
?>
<body>
<table width="700" border="0" cellpadding="0" cellspacing="0">
  <tr> 
    <td width="700" height="100" valign="top">
	  <form name="Interface_frm" id="Interface_frm" method="post" action="secure_data.php">
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <!--DWLayoutTable-->
          <tr> 
            <td height="50" colspan="2" align="center">Threepenny Review Secure Data Retrieval</td>
          </tr>
          <tr> 
            <td width="350" height="50" align="center">
			  <select name="FV_Action_Select" id="FV_Action_Select">
			    <option value="1" <?php if(!$_POST['FV_Action_Select'] || $_POST['FV_Action_Select'] == 1) {echo 'selected="selected"';} ?> >Show New Records</option>
				<option value="2" <?php if($_POST['FV_Action_Select'] == 2) {echo 'selected="selected"';} ?> >Show Processed Records</option>
				<option value="3" <?php if($_POST['FV_Action_Select'] == 3) {echo 'selected="selected"';} ?> >Show All Records</option>
              </select>
			</td>
            <td width="350" align="center"> <input type="submit" name="Go" value="Go" /> 
            </td>
          </tr>
        </table>
	</td>
  </tr>
  <tr> 
    <td height="223" valign="top">
<?php
  while($Row = mysql_fetch_assoc($Get_Data_Result)) {
    foreach($Row as $Field_Name => $Field_Value) {
	  $$Field_Name = $Field_Value;
	}
	$Delete_Name = 'FV_Delete_Me_';
	$Delete_Name .= $c_id;
	$Process_Name = 'FV_Process_Me_';
	$Process_Name .= $c_id;
	if($c_processed == 1) {
	  $Processed = 'checked="checked"';
	}
	else {
	  $Processed = '';
	}
	
    print <<< END
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
        <!--DWLayoutTable-->
		<tr>
		    <td width="700" colspan="4" bgcolor="#FFFF00">$c_item_ordered</td>
		</tr>
        <tr>
          <td height="21" colspan="2" align="center" bgcolor="#00CCFF">Billing Information</td>
          <td colspan="2" align="center" bgcolor="#66CC99">Shipping Information</td>
        </tr>
        <tr>
          <td height="5" colspan="2" valign="top"><img src="../images/spacer.gif" width="1" height="1" /></td>
          <td colspan="2" valign="top"><img src="../images/spacer.gif" width="1" height="1" /></td>
        </tr>
        <tr>
          <td width="56" height="21" valign="top">Name:</td>
		  <td width="292" valign="top">$c_first_name $c_last_name</td>
          <td width="56" valign="top">Name:</td>
          <td width="296" valign="top">$co_first_name $co_last_name</td>
        </tr>
        <tr> 
          <td height="21" valign="top">Address:</td>  
          <td valign="top">
		    $c_street_address<br />
			$c_city, $c_state $c_zip<br />
		  </td>
          <td valign="top">Address:</td>  
          <td valign="top">
		    $co_street_address<br />
			$co_city, $co_state $co_zip<br />
		  </td>
        </tr>
        <tr> 
          <td height="21" valign="top">Phone:</td>  
          <td valign="top">$c_phone</td>
          <td valign="top">Phone:</td>  
          <td valign="top">$co_phone</td>
        </tr>
        <tr> 
          <td height="21" valign="top">Email:</td>  
          <td valign="top">$c_email</td>
          <td valign="top">Email:</td>  
          <td valign="top">$co_email</td>
        </tr>
        <tr> 
          <td height="5" colspan="2" valign="top"><img src="../images/spacer.gif" width="1" height="1" /></td>
          <td colspan="2" valign="top"><img src="../images/spacer.gif" width="1" height="1" /></td>
        </tr>
        <tr> 
          <td height="21" colspan="2" align="center" valign="top" bgcolor="#FF0000">Credit Card Information</td>
          <td colspan="2" align="center" valign="top">Comments</td>
        </tr>
        <tr> 
          <td height="5" colspan="2" valign="top"><img src="../images/spacer.gif" width="1" height="1" /></td>
          <td colspan="2" valign="top"><img src="../images/spacer.gif" width="1" height="1" /></td>
        </tr>
        <tr> 
          <td height="21" valign="top">Type:</td>  
            <td valign="top">$c_card_type</td>
            <td colspan="2" rowspan="3" valign="top">$co_comments</td>
        </tr>
        <tr> 
          <td height="21" valign="top">Number:</td> 
            <td valign="top">$c_card_number</td>
        </tr>
        <tr>
          <td height="21" valign="top">Exp:</td>
            <td valign="top">$c_expiration</td>
        </tr>
        <tr> 
          <td height="19" colspan="2" valign="top">
		    Processed: <input type="checkbox" name="$Process_Name" id="$Process_Name" value="$c_id" $Processed/>
            Delete: <input type="checkbox" name="$Delete_Name" id="$Delete_Name"; value="$c_id"/> </td>
          <td valign="top">Date:</td>
          <td valign="top">$c_date_created</td>
        </tr>
		<tr>
		  <td height="10" colspan="4" valign="top"><img src="../images/spacer.gif" width="1" height="1" /></td>
		</tr>
      </table>
END;
}
mysql_close($dbh);
?>
</form>
	  </td>
  </tr>
</table>
</body>
</html>


#2 ChaosXero

ChaosXero
  • Members
  • PipPipPip
  • Advanced Member
  • 80 posts

Posted 20 July 2006 - 04:49 PM

elseif($_POST['FV_Action_Select'] == 2) {
    $Get_Data .= " AND Customer.c_processed IS NOT NULL ORDER BY 'date' ";
  }
Give that a try. (Change 'date' if that isnt your date feilds name)

#3 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 20 July 2006 - 05:27 PM

don't put quote marks around date
Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...

#4 muddy004

muddy004
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 20 July 2006 - 07:02 PM

Can you tell what the exact date field is that I need to use from the code above?

#5 ChaosXero

ChaosXero
  • Members
  • PipPipPip
  • Advanced Member
  • 80 posts

Posted 20 July 2006 - 07:04 PM

Not sure which you want, but most likely:
c_date_created




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users