Log in

View Full Version : what is wrong with this sql commands?



185
10-24-2007, 05:42 AM
Hi,

I need to display data in atble format in pdf..when i am using FPDF and below slq command i receive the following error...


The user will select the year, based on the year the data will be displayed in table format in pdf…I receive the below errors….

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 '-45' group by `Date`, Node_ID' at line 1
Query: -45' group by `Date`, Node_ID


My codes are as bellows:

$sql = "SELECT Node_ID ,Date, AVG(voltage),AVG(Temper), AVG(light),AVG(accel_x), AVG(accel_y), AVG(mag_x), AVG(mag_y), AVG(mic) from suhu where Date >'{$_POST['year']}-01-01' and Date <= '{$_POST['year']}-12-31'
group by `Date`,Node_ID ";

Do you know where is the error?



The user will select the year,based on the selected year ,data will be displayed.before ths ,i receive the output,but whn i am trying convert the output into pdf format,i got errors...my full coding is belows:



<?php
define('FPDF_FONTPATH','font/');
require('mysql_table.php');

class PDF extends PDF_MySQL_Table
{
function Header()
{
//Title
$this->SetFont('Arial','',18);
$this->Cell(0,6,'Average data order by node ID and Date',0,1,'C');
$this->Ln(10);
//Ensure table header is output
parent::Header();
}
}

//Connect to database
mysql_connect('localhost','','');
mysql_select_db('wsn');
$pdf=new PDF();
$pdf->Open();
$pdf->AddPage();

$pdf->Table('SELECT Node_ID as node, AVG(voltage) as volt,AVG(Temper) as temper, AVG(light) as light,AVG(accel_x) as accel_x, AVG(accel_y) as accel_y, AVG(mag_x) as mag_x, AVG(mag_y)as mag_y, AVG(mic) as mic,Date as date from suhu where Date >='.'\''.$_POST['year']-01-01 .'\''.' AND Date <='.'\''.$_POST['year']-12-31 .'\''.' group by `Date`, Node_ID');
$pdf->AddPage();
$pdf->Output();
?>



Help me...:(


thank you

boogyman
10-24-2007, 12:42 PM
$sql = "SELECT Node_ID ,Date, AVG(voltage),AVG(Temper), AVG(light),AVG(accel_x), AVG(accel_y), AVG(mag_x), AVG(mag_y), AVG(mic) from suhu where Date >'{$_POST['year']}-01-01' and Date <= '{$_POST['year']}-12-31'
group by `Date`,Node_ID ";

the error is most likely occuring at the () braces. are those the EXACT name that you have in the database? if so I would advise to change them as they can cause
also your browser may not support the inline php quirk.

185
10-27-2007, 12:03 PM
thanks,

I found the soultion ready....