Forum Moderators: open

Message Too Old, No Replies

left fun

         

bleak26

6:02 pm on Dec 22, 2005 (gmt 0)

10+ Year Member



Hello and thanks for all the help so far webmaster world peeps. Hopefully you can help me once again.

I'm having a problem with the sql statement below. When i use LEFT i can no longer access text from the array of results returned from my MySQL database eg; <p>".$row['text']."</p>

Can you think of any reason why this might be happening and how i might access the text index of the row array, when i use LEFT?

//this is the sql statement i am using
$sqlstatement = "Select account.memid, account.surname, account.firstname, account.posteddate ,LEFT(account.text, 80)
from account where date_sub(curdate(), interval 21 day) ORDER BY
account.posteddate DESC";

mattglet

6:22 pm on Dec 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I could be wrong, but I think you need to specify the column name again:

$sqlstatement = "Select account.memid, account.surname, account.firstname, account.posteddate ,LEFT(account.text, 80) AS text
from account where date_sub(curdate(), interval 21 day) ORDER BY
account.posteddate DESC";

Note the "AS text" after your LEFT function.

aspdaddy

6:42 pm on Dec 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thats how functions work in MSSQL Otherwise its just returened as Expr1

FalseDawn

7:26 pm on Dec 22, 2005 (gmt 0)

10+ Year Member



It's not a good practise to alias a returned field using the name of a datatype.

I would choose a different alias than "text"

FalseDawn

7:27 pm on Dec 22, 2005 (gmt 0)

10+ Year Member



Having said that, I would never have called the field itself "text" in the first place :)

henry0

12:28 pm on Dec 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



isn't it a reserved name list somewhere?

there are names that should never be used for they are "Reserved"

aspdaddy

1:06 pm on Dec 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Its a datatype in MS SQL but not reserverd, it lets you name columns and select from them

henry0

1:54 pm on Dec 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Got it I was thinking within my environment
MySQL and PHP :)