You are here: Re: 2nd Newbie question - results page wont load with order by in query « PHP SQL « IT news, forums, messages
Re: 2nd Newbie question - results page wont load with order by in query

Posted by J.O. Aho on 12/22/07 11:11

glyn@amethystmailing.co.uk wrote:
> HI the code is as below appologies if its a bit messy its my first
> attempt at this.
> //setup query
> $result = mysql_query("select tbldocketref.jobno, tbljob_info.`job

I always recommend you to save the query to a variable, this gives the great
advantage that you can print out the query and see if it's set right.


$query="SELECT tbldocketref.jobno, tbljob_info.`job description`,
clients.Clientname, tbldocketref.group, tbldocketref.docketno,
DATE_FORMAT(tbldocketref.`mail date`, '%d/%m/ %Y') AS `Mail date`,
tblmsservice.name AS MS_Service, tblmailpieceformat.format AS Pack_Format,
tbldocketref.`qty mailsort`, tbldocketref.`qty std tarrif`,
tbldocketref.`qty os`, tbldocketref.`item weight`
FROM tbldocketref
LEFT JOIN tbljob_info on (tbldocketref.JobNo = tbljob_info.jobno)
LEFT JOIN clients on (tbldocketref.client = clients.clientid)
LEFT JOIN tblmailpieceformat on (tbldocketref.`mail piece format` =
tblmailpieceformat.`mailpiece id`)
LEFT JOIN tblmsservice on (tbldocketref.`ms service if app` =
tblmsservice.serviceid)
WHERE clients.clientname = '{$_POST['client']}' ORDER BY `Mail date`";

> //the next statement is the one that dosnt work
> //order by `mail date`
$result = mysql_query($query)
or die("Querry Error! Error: ".mysql_error()." Query: ".$query);

The error message will be more useful and now you can copy paste the query
that the PHP was trying to use to the mysql client.

I ALWAYS use the same case on the characters, so I would write `mail date` as
`Mail date`.

Using single quotes around values will make it easier for you to see where to
add ORDER BY. I think it's best to use capital characters for SQL functions,
this way it make it easier for me to read the query.




--

//Aho

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация