marketboy Posted November 19, 2008 Share Posted November 19, 2008 I need to be able to (within my query) place two variables into another variable as something else. For example this is snippet of the query I have now: $sql = "SELECT ID, FirstName, MiddleName, LastName FROM Accounts order by ID "; I have it print out a csv file with all of the information in different columns, so I would have a header with the names of my fields, and each column holds thier values. What I need to do is put those first three variables together within the query AS Title. In theory this is what I would need: $sql = "SELECT ID, FirstName, MiddleName, LastName, FirstName + MiddleName + LastName AS Title FROM Accounts order by ID "; When I do something along these lines, it creates the title field in the header, but tries to mathematically add the values together obviously. I haven't been able to find much help with the AS statement or how I might be able to do this. Thank you in advance. Link to comment https://forums.phpfreaks.com/topic/133388-solved-select-as-statement-with-multiple-variables/ Share on other sites More sharing options...
xtopolis Posted November 19, 2008 Share Posted November 19, 2008 http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_concat or http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_concat-ws ... , CONCAT(FirstName,MiddleName,LastName) AS Title // FirstNameMiddleNameLastName or with a separator ..., CONCAT_WS('-',FirstName,MiddleName,LastName) AS Title //FirstName-MiddleName-LastName untested Link to comment https://forums.phpfreaks.com/topic/133388-solved-select-as-statement-with-multiple-variables/#findComment-693765 Share on other sites More sharing options...
marketboy Posted November 19, 2008 Author Share Posted November 19, 2008 Beautiful. Thanks so much. That was exactly what I needed. Link to comment https://forums.phpfreaks.com/topic/133388-solved-select-as-statement-with-multiple-variables/#findComment-693780 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.