Jump to content

[SOLVED] PHP HIGHEST TO LOWEST SORT


canalb

Recommended Posts

I'm new with PHP script. have a CRM site that i created but have trouble with sorting the customer notes from the news to the oldest. Please help!

 

this is the code:

<?php require_once('includes/config.php');

$page = customers;

?>

<?php

session_start();

if (!$_SESSION['admin']) {

header('Location: index.php');

}

if (!function_exists("GetSQLValueString")) {

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

{

  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

 

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

 

  switch ($theType) {

    case "text":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

      break;   

    case "long":

    case "int":

      $theValue = ($theValue != "") ? intval($theValue) : "NULL";

      break;

    case "double":

      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";

      break;

    case "date":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

      break;

    case "defined":

      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;

      break;

  }

  return $theValue;

}

}

 

$edit = "";

if (isset($_GET['id'])) {

$edit = "WHERE notes_customerid = ".$_GET['id']."";

}

 

mysql_select_db($database_customers, $customers);

$query_customernotes = "SELECT *,date_format(notes_date, '%Y-%c-%e') as notes_date FROM customer_notes $edit";

$customernotes = mysql_query($query_customernotes, $customers) or die(mysql_error());

$row_customernotes = mysql_fetch_assoc($customernotes);

$totalRows_customernotes = mysql_num_rows($customernotes);

$row_count = 0;

 

 

$colname_customers = "-1";

if (isset($_GET['id'])) {

  $colname_customers = (get_magic_quotes_gpc()) ? $_GET['id'] : addslashes($_GET['id']);

}

mysql_select_db($database_customers, $customers);

$query_customers = sprintf("SELECT * FROM customers WHERE id = %s", GetSQLValueString($colname_customers, "int"));

$customers = mysql_query($query_customers, $customers) or die(mysql_error());

$row_customers = mysql_fetch_assoc($customers);

$totalRows_customers = mysql_num_rows($customers);

 

$colname_contacts = "-1";

if (isset($_GET['id'])) {

  $colname_contacts = (get_magic_quotes_gpc()) ? $_GET['id'] : addslashes($_GET['id']);

}

mysql_select_db($database_customers);

$query_contacts = sprintf("SELECT * FROM customer_contacts WHERE contact_customer = %s", GetSQLValueString($colname_contacts, "int"));

$contacts = mysql_query($query_contacts) or die(mysql_error());

$row_contacts = mysql_fetch_assoc($contacts);

$totalRows_contacts = mysql_num_rows($contacts);

 

 

?>

 

 

<?php

$_SESSION['previous'] = $_SERVER['REQUEST_URI'];

 

?>

 

<!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>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title><?php echo $row_customers['company']; ?>  |  Simple Customer: Customer Details</title>

<link href="customers.css" rel="stylesheet" type="text/css" />

</head>

 

<body>

 

<?php include('includes/header.php'); ?>

<table width="540" align="center" cellpadding="10" cellspacing="0">

 

    <tr valign="baseline">

      <td colspan="5" align="left" valign="middle" nowrap="nowrap"><h1>Customer Information </h1></td>

    </tr>

    <tr valign="baseline">

      <td colspan="5" align="left" valign="middle" nowrap><table width="100%" border="0" cellspacing="0" cellpadding="0">

        <tr>

          <td width="211"><strong><?php echo $row_customers['prefix']; ?> <?php echo $row_customers['firstname']; ?> <?php echo $row_customers['lastname']; ?></strong><?php if ($row_customers['title']) { ?>, <strong><?php echo $row_customers['title']; ?></strong><?php } ?><br />

            <?php echo $row_customers['company']; ?><br />

            <a href="mailto:<?php echo $row_customers['email']; ?>" class="links"><?php echo $row_customers['email']; ?></a><br />

            <?php echo $row_customers['street']; ?><br />

            <?php echo $row_customers['city']; ?>, <?php echo $row_customers['state']; ?> <?php echo $row_customers['zip']; ?><br />

            <?php echo $row_customers['phone']; ?> (work) <br />

            <?php if ($row_customers['phone_other']) { ?><?php echo $row_customers['phone_other']; ?> (fax)<br />

            <?php } ?>

            <a href="<?php echo $row_customers['website']; ?>" target="_blank" class="links"><?php echo $row_customers['website']; ?></a><br />

            <br /><?php if ($row_customers['comments']) { ?>

            <strong>Comments:</strong> <?php echo $row_customers['comments']; ?><br />

            <?php } ?></td>

          <td width="307" valign="top"><div class="rightcolumn">

            <p><strong>Actions</strong><a href="edit-customer.php?id=<?php echo $row_customers['id'];?>" class="links"><br />

              </a><a href="notes.php?customer=<?php echo $row_customers['id'];?>" class="links">add note<br />

              </a><a href="contact.php?customer=<?php echo $row_customers['id'];?>" class="links">add contact </a><a href="add-notes.php?id=<?php echo $row_customers['id'];?>" class="links">              </a>

              <?php if ($row_admininfo['admin_level']==1) { ?><a href="add-customer.php?id=<?php echo $row_customers['id'];?>" class="links"><br />

                edit</a><?php } ?></p>

            <p><?php if ($row_admininfo['admin_level']==1) { ?><a href="delete.php?id=<?php echo $row_customers['id'];?>" class="links">delete </a><?php } ?></p>

          </div>

            <p> </p>          </td>

        </tr>

      </table>      <p><br />     

        </p>      </td>

    </tr>

<?php if ($row_customernotes['notes_id']>0) { ?>

    <tr valign="baseline">

      <td width="165" align="left" valign="middle" nowrap><h1>Customer Notes </h1></td>

      <td colspan="3" align="left" valign="middle"> </td>

    </tr>

      <?php do { ?> 

<?php $row_count++;?>

<tr bgcolor="<?php if ($row_count %2) { echo "#F4F4F4"; } ?>"  valign="baseline">

 

      <td colspan="4" align="left" valign="middle"><strong><?php echo $row_customernotes['notes_title']; ?></strong><br />

        <?php echo $row_customernotes['notes_description']; ?><br />

 

<?php

$date = $row_customernotes['notes_date'];

list($year, $month, $day) = split('[-.-]', $date);

?>

 

        Posted: <span class="blogdate"><?php echo "$month/$day/$year"; ?><br />

      <a href="notes.php?notes_id=<?php echo $row_customernotes['notes_id']?>" class="links">edit</a> | <a href="delete.php?notes_id=<?php echo $row_customernotes['notes_id']?>" class="links">delete</a></span></td>

      </tr><?php } while ($row_customernotes = mysql_fetch_assoc($customernotes)); ?>

<?php } ?>

<?php if ($totalRows_contacts > 0) { ?>

<tr valign="baseline">

  <td colspan="4" align="left" valign="middle" nowrap><h1>Contacts</h1></td>

</tr>

 

  <?php do { ?> 

    <?php $row_count++;?>

    <tr bgcolor="<?php if ($row_count %2) { echo "#F4F4F4"; } ?>"  valign="baseline">

      <td width="165" align="left" valign="middle" nowrap><a href="contact.php?contact=<?php echo $row_contacts['contact_id']?>" class="links"><?php echo $row_contacts['contact_name']?></a></td>

      <td width="133" align="left" valign="middle" nowrap><?php echo $row_contacts['contact_phone']?></td>

      <td width="133" align="left" valign="middle" nowrap><a href="mailto:<?php echo $row_contacts['contact_email']?>" class="links"><?php echo $row_contacts['contact_email']?></a></td>

      <td width="47" align="left" valign="middle" nowrap><a href="delete.php?contact=<?php echo $row_contacts['contact_id'];?>" class="links">

        <?php if ($row_admininfo['admin_level']==1) { ?>

      delete

      <?php } ?>

      </a></td>

    </tr>

    <?php } while ($row_contacts = mysql_fetch_assoc($contacts)); ?>

  <?php  } ?>

 

</table>

   

 

<?php include('includes/footer.php'); ?>

<p> </p>

</body>

</html>

<?php

mysql_free_result($customers);

 

mysql_free_result($contacts);

 

mysql_free_result($customernotes);

?>

 

Link to comment
https://forums.phpfreaks.com/topic/140834-solved-php-highest-to-lowest-sort/
Share on other sites

This

 

$query_customernotes = "SELECT *,date_format(notes_date, '%Y-%c-%e') as notes_date FROM customer_notes $edit";

 

Needs to be

$query_customernotes = "SELECT *,date_format(notes_date, '%Y-%c-%e') as notes_date FROM customer_notes $edit ORDER BY notes_date DESC";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.