SQL syntax?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi I am having problems (yep me again) with my sql, I have looked and tried
different things (ASC, DESC, etc) but it same error:
Here is the error:
 You have an error in your SQL syntax; check the manual that corresponds to
your MySQL server version for the right syntax to use near 'ORDER BY
StartDate DESC' at line 2 <--------------and the actual line the code is on
is line 21 not 2 so that is weird...and I had a comma between DESC and the
field but nothing

Code:
   $sql = "SELECT WorkOrderID AS Work_Order_ID, DATE_FORMAT(StartDate, '%b.
%e, %Y %l:%i %p') AS Start_Date,
    DATE_FORMAT(EndDate, '%b. %e, %Y %l:%i %p') AS End_Date, ";
    $sql .= "Advertiser AS Advertiser_Name,AccountNum AS Account_Number,
Impressions AS Ad_Impressions, ";
    $sql .= "AdSize AS Ad_Size,  CPM AS CPM_Rate, ";
    $sql .= "ORDER BY StartDate DESC";

could it be the AS, <---- I copied that from another code--- I am trying to
make a report from the table....Here is my full script:

<?php
include("../inc/dbconn_open.php");

if (empty($_SESSION['AdminLogin']) OR $_SESSION['AdminLogin'] <> 'OK' ){
    header ("Location: LogOut.php");
}

    $query = "SELECT WorkOrderID, Advertiser, AccountNum, Impressions,
AdSize, StartDate, EndDate, CPM,  OnlineDate FROM workorderform";
    $result = mysql_query ($query) or die(mysql_error());
    $row = mysql_fetch_object ($result);
    if ($row->UserReport == "NO") {
        header ("Location: Welcome.php?AdminID=$AdminID&msg=Sorry, you do
not have access to that page.");
    }



    $sql = "SELECT WorkOrderID AS Work_Order_ID, DATE_FORMAT(StartDate, '%b.
%e, %Y %l:%i %p') AS Start_Date,
    DATE_FORMAT(EndDate, '%b. %e, %Y %l:%i %p') AS End_Date, ";
    $sql .= "Advertiser AS Advertiser_Name,AccountNum AS Account_Number,
Impressions AS Ad_Impressions, ";
    $sql .= "AdSize AS Ad_Size,  CPM AS CPM_Rate, ";
    $sql .= "ORDER BY StartDate DESC";


    $export = mysql_query($sql) or die(mysql_error());
    $row = mysql_fetch_object ($result);
    $fields = mysql_num_fields($export);


$header = "";
$value = "";
$data = "";

    for ($i = 0; $i < $fields; $i++) {
        $header .= mysql_field_name($export, $i) . "\t";
    }

    while($row2 = mysql_fetch_row($export)) {
        $line = '';
        foreach($row2 as $value)
{
            if ((!isset($value)) OR ($value == "")) {
                $value = "\t";
            } else {
                $value = str_replace('"', '""', $value);
                $value = '"' . $value . '"' . "\t";
            }
            $line .= $value;
        }
        $data .= trim($line)."\n";
    }
    $data = str_replace("\r","",$data);

    if ($data == "") {
        $data = "\n(0) Records Found!\n";
    }

    header("Content-type: application/x-msdownload");
    header("Content-Disposition: attachment; filename=AdDates_Report.xls");
    header("Pragma: no-cache");
    header("Expires: 0");
    print "$header\n$data";


?>

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux