Jump to content

[SOLVED] order by desc


sandbudd

Recommended Posts

I have a auto increment with the field id , how do I do an order by descent to display from first to last...the way it is now it just displays random?

 

here are the two files...the add to the database and the display

 

<?php

//This is the directory where images will be saved
$target = "images/";
$target = $target . basename( $_FILES['photo']['name']);

//This gets all the other information from the form
$company=$_POST['company'];
$address=$_POST['address'];
$city=$_POST['city'];
$state=$_POST['state'];
$phone=$_POST['phone'];
$email=$_POST['email'];
$website=$_POST['website'];
$pic=($_FILES['photo']['name']);

// Connects to your Database
mysql_connect("mysql500.hostexcellence.com", "sandbud_fwr", "Pavilion4628") or die(mysql_error()) ;
mysql_select_db("sandbud_fwr") or die(mysql_error()) ;

//Writes the information to the database
mysql_query("INSERT INTO `employees` VALUES ('$id', '$company', '$address', '$city', '$state', '$phone', '$email', '$website', '$pic')") ;

//Writes the photo to the server
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
{

//Tells you if its all ok
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
}
else {

//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
?> 

 

<?php require_once('../Connections/fwragain.php'); ?>
<?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;
}
}

$maxRows_Recordset1 = 10;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
  $pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;

mysql_select_db($database_fwragain, $fwragain);
$query_Recordset1 = "SELECT * FROM employees";
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $fwragain) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);

if (isset($_GET['totalRows_Recordset1'])) {
  $totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
  $all_Recordset1 = mysql_query($query_Recordset1);
  $totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
<!--
.style3 {font-family: Arial, Helvetica, sans-serif; font-size: 11px; }
.style4 {
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
font-weight: bold;
}
.style1 {	font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 11px;
}
.style2 {	font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 14px;
}
.style5 {font-family: Verdana, Arial, Helvetica, sans-serif}
-->
</style>
</head>

<body>
<table width="383" border="0" cellpadding="5" cellspacing="5">
  
  <?php do { ?>
    <tr>
      <td width="195"><span class="style4"><?php echo $row_Recordset1['company']; ?></span><br />
        <span class="style3"><?php echo $row_Recordset1['address']; ?></span><br />
        <span class="style3"><?php echo $row_Recordset1['city']; ?></span><span class="style3">,</span><span class="style3"><?php echo $row_Recordset1['state']; ?></span><br />
        <span class="style3"><?php echo $row_Recordset1['phone']; ?></span><br />
        <span class="style3"><a href="http://<?php echo $row_Recordset1['website']; ?>" target="_blank"><?php echo $row_Recordset1['website']; ?></a></span><br /></span>

        
      <td width="104" colspan="4" align="center" valign="middle"><?php echo "<img src=http://www.fortwaynerestaurant.net/images/".$row_Recordset1['photo'] ."> "; ?></td>
    </tr>
    
    
    <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>

</body>
</html>
<?php
mysql_free_result($Recordset1);
?>

Link to comment
https://forums.phpfreaks.com/topic/151995-solved-order-by-desc/
Share on other sites

mysql_select_db($database_fwragain, $fwragain);
$query_Recordset1 = "SELECT * FROM employees ORDER BY ASC";
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $fwragain) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);

Link to comment
https://forums.phpfreaks.com/topic/151995-solved-order-by-desc/#findComment-798223
Share on other sites

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.