在phpmyadmin中查询成功但在php中失败

I would like to ask about the query to select the last record in a table which can match a specific condition.

The following code can successfully execute and gives out the correct record in phpmyadmin

SELECT TYPE FROM log WHERE TechID=4 ORDER By LogTime DESC LIMIT 1

However,when I form the query in my php file and execute, it gives out error.

$query2 = "SELECT Type FROM Log WHERE TechID=".$row1['TechID']."ORDER BY LogTime DESC LIMIT 1"

here is the error message:

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 'BY LogTime DESC LIMIT 1' at line 1.

Can anyone tell me what is happening, myquery should be same as the one I use in the phpmyadmin

Below are the sample records I created to test my file.

LogID TechID ClientID SiteID Type     LogTime
1     2      5        1      Checkin  2012/07/04 09:00
2     4      5        1      Checkin  2012/07/04 09:00
3     2      5        1      Checkout 2012/07/04 10:00

I'd put a space before the order statement.

" ORDER"

Another thing that might be an issue (though not here): Strings have to be escaped with double quotes in PHP, not single quotes (please don't ask me why). Thus,

mysqli_query("select * from tabel where name = 'peter'");

will be false, and

mysqli_query("select * from tabel where name = \"peter\"");

or

mysqli_query('select * from tabel where name = "peter"');

will succeed.