can anyone help?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post 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?
ckuipers
Forum Commoner
Posts: 61
Joined: Mon Mar 24, 2003 6:10 am

Post 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 *.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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`
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post 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??
Last edited by mohson on Tue Jan 18, 2005 8:48 am, edited 1 time in total.
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

is your monitor on?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post 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



?>
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post 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??
ckuipers
Forum Commoner
Posts: 61
Joined: Mon Mar 24, 2003 6:10 am

Post 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 *,
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post 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??
ckuipers
Forum Commoner
Posts: 61
Joined: Mon Mar 24, 2003 6:10 am

Post by ckuipers »

Did you put quotes around your query

$query = "SELECT .... ";
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
ckuipers
Forum Commoner
Posts: 61
Joined: Mon Mar 24, 2003 6:10 am

Post by ckuipers »

mysql will in fact generate an error on this, error nr. 1064
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

that's only if you didn't specify the table to take them from... notice I used a table alias. Which works.
ckuipers
Forum Commoner
Posts: 61
Joined: Mon Mar 24, 2003 6:10 am

Post by ckuipers »

Didn't see that. Sorry...
Post Reply