Page 2 of 3

Posted: Tue Jan 18, 2005 6:04 am
by mohson

Code: Select all

$query = "SELECT DATE_FORMAT('%d/%m/%y', 'dateoflastcontact') 
	AS dateoflastcontact, DATE_FORMAT('%d/%m/%y', 'datecontactagain') 
	AS datecontactagain, * FROM people ORDER BY firstname";
still getting this error message:

Error in query: You have an error in your SQL syntax near '* FROM people ORDER BY firstname' at line 3

any ideas?

Posted: Tue Jan 18, 2005 7:11 am
by ckuipers
I think you can't use * when you've already specified columns you want to select. Select all the columns you need by name and ommit the *.

Posted: Tue Jan 18, 2005 8:22 am
by feyd
apologies, the order of selection was a bit off:

Code: Select all

SELECT *, DATE_FORMAT('%d/%m/%y', `dateoflastcontact`)
   AS `dateoflastcontact`, DATE_FORMAT('%d/%m/%y', `datecontactagain`)
   AS `datecontactagain` FROM `people` ORDER BY `firstname`

Posted: Tue Jan 18, 2005 8:36 am
by mohson
$query = SELECT * DATE_FORMAT('%d/%m/%y', `dateoflastcontact`)
AS `dateoflastcontact`, DATE_FORMAT('%d/%m/%y', `datecontactagain`)
AS `datecontactagain` FROM `people` ORDER BY `firstname`



this is wierd but now the screen has just gone blank


any ideas whats wrong??

Posted: Tue Jan 18, 2005 8:38 am
by magicrobotmonkey
is your monitor on?

Posted: Tue Jan 18, 2005 8:38 am
by feyd
might have an (fatal) error you aren't seeing.. make sure error_reporting is set to E_ALL and such:

Code: Select all

error_reporting(E_ALL);
ini_set('display_errors', '1');
place that code at the very beginning of the file.

Posted: Tue Jan 18, 2005 8:55 am
by mohson
Someone suggested this before -

error_reporting(E_ALL);
ini_set('display_errors', '1');

this doesnt have any effect,

eg

Code: Select all

<?php include "dyn.header"; ?>
<!-- Please don't remove these comments -->
<!-- Content Start -->


error_reporting(E_ALL); 
ini_set('display_errors', '1');


REST OF CODE



?>

Posted: Tue Jan 18, 2005 9:08 am
by mohson
Is it true that you cant use the star once you have specified coloums? as someone suggested above??

Code: Select all

$query = SELECT * DATE_FORMAT('%d/%m/%y', `dateoflastcontact`) 
AS `dateoflastcontact`, DATE_FORMAT('%d/%m/%y', `datecontactagain`) 
AS `datecontactagain` FROM `people` ORDER BY `firstname`

this is wierd but now the screen has just gone blank


any ideas whats wrong??

Posted: Tue Jan 18, 2005 9:16 am
by ckuipers
You can use it before, but not after you've specified columns. This is MySQL 4, not sure about 3.

However, you did miss the ,
it's SELECT *,

Posted: Tue Jan 18, 2005 9:24 am
by mohson
thanks that was just a typo though as I thought the (,) might be causing a problem didnt matter though because it doesnt work with or wothout it can you spot anything else that might be wrong

Also I used the error reporting but it doesnt do anything (see post above) have I placed it in the correct place in the example above??

Posted: Tue Jan 18, 2005 9:32 am
by ckuipers
Did you put quotes around your query

$query = "SELECT .... ";

Posted: Tue Jan 18, 2005 9:35 am
by feyd
you actually can use the asterix after columns have been specified:

Code: Select all

SELECT `some column`, a.* FROM `table` a
the problem is, if `some column` matches another column name returned by the asterix, and you fetch using associative, you will get a collision, and the latter column will prevail.

Posted: Tue Jan 18, 2005 9:40 am
by ckuipers
mysql will in fact generate an error on this, error nr. 1064

Posted: Tue Jan 18, 2005 9:48 am
by feyd
that's only if you didn't specify the table to take them from... notice I used a table alias. Which works.

Posted: Tue Jan 18, 2005 9:50 am
by ckuipers
Didn't see that. Sorry...