Reply
Query retrieving data as number when data type is a varchar with text
Old 07-03-2008, 05:49 AM Query retrieving data as number when data type is a varchar with text
drew22299's Avatar
Skilled Talker

Posts: 89
Location: Wiltshire, UK
I have a field in my people table called 'client' and it stores a text string using varchar. But when I get the data from the table and print it using PHP it prints the number 1 for every record, but for all of the other data retrieved for the other fields in the same record it prints out the correct data.

For example, this is the query I am using:

PHP Code:
$peopleIds =& $db->query("SELECT * FROM people P, organisation O, organisationPeople OP WHERE P.personId = OP.personId AND O.organisationId = OP.organisationId AND OP.organisationId = '$_GET[id]' ORDER BY P.first_name ASC");
        
checkDBError($peopleIds);
 
while(
$peopleIds->fetchInto($peopleId))
    {
          
$peopleId['firstName']; // Prints the first name
          
$peopleId['client']; // Prints 1 for every record
    

Any ideas?

Thanks,
__________________
www.hotlista.co.uk
drew22299 is offline
Reply With Quote
View Public Profile Visit drew22299's homepage!
 
When You Register, These Ads Go Away!
Old 07-03-2008, 05:53 AM Re: Query retrieving data as number when data type is a varchar with text
drew22299's Avatar
Skilled Talker

Posts: 89
Location: Wiltshire, UK
I fixed this by changing the name of the client field to ISclient and it now displays the data stored for that field. I'm guessing client is a reserved word in MySQL?
__________________
www.hotlista.co.uk
drew22299 is offline
Reply With Quote
View Public Profile Visit drew22299's homepage!
 
Old 07-03-2008, 07:40 AM Re: Query retrieving data as number when data type is a varchar with text
Skilled Talker

Posts: 94
No, but here is a great link to check in the future

http://dev.mysql.com/doc/refman/5.0/...ved-words.html
__________________
Sell Templates? Try our Template Monster WebAPI absolutely free! See a live Template Shop Demo
ChadR is offline
Reply With Quote
View Public Profile
 
Old 07-03-2008, 07:42 AM Re: Query retrieving data as number when data type is a varchar with text
Skilled Talker

Posts: 94
Maybe a type-0?

organisation

organization

I know I am American and we have a funny way of spelling so maybe it's different there.
__________________
Sell Templates? Try our Template Monster WebAPI absolutely free! See a live Template Shop Demo
ChadR is offline
Reply With Quote
View Public Profile
 
Old 07-03-2008, 07:54 AM Re: Query retrieving data as number when data type is a varchar with text
drew22299's Avatar
Skilled Talker

Posts: 89
Location: Wiltshire, UK
Thanks for the link CharR, I didn't come accross that one I don't think it's the spelling of the word organisation because it prints out the data from that field as long as it's not called action I had a similar problem a few weeks ago when I called a field phone and then changed it to phoneNum and it worked lol maybe it's something to do with how the server is setup?
__________________
www.hotlista.co.uk
drew22299 is offline
Reply With Quote
View Public Profile Visit drew22299's homepage!
 
Old 07-03-2008, 04:40 PM Re: Query retrieving data as number when data type is a varchar with text
chrishirst's Avatar
Super Moderator

Posts: 13,588
Location: Blackpool. UK
I'd suggest that "client" could have been an ambiguous field name because of the use of * instead of a fieldlist.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 07-04-2008, 08:00 AM Re: Query retrieving data as number when data type is a varchar with text
Skilled Talker

Posts: 94
Quote:
Originally Posted by chrishirst View Post
I'd suggest that "client" could have been an ambiguous field name because of the use of * instead of a fieldlist.

Chris is probably right, if you had 2 or more tables with the "client" column in it then that would happen. Using SELECT * is almost always a bad idea.
__________________
Sell Templates? Try our Template Monster WebAPI absolutely free! See a live Template Shop Demo
ChadR is offline
Reply With Quote
View Public Profile
 
Old 07-07-2008, 06:02 AM Re: Query retrieving data as number when data type is a varchar with text
drew22299's Avatar
Skilled Talker

Posts: 89
Location: Wiltshire, UK
chrishirst, ChadR the query did have SELECT * Thanks for your comments, I didn't know that using SELECT * could make problems
__________________
www.hotlista.co.uk

Last edited by drew22299 : 07-07-2008 at 06:05 AM.
drew22299 is offline
Reply With Quote
View Public Profile Visit drew22299's homepage!
 
Old 07-07-2008, 07:05 PM Re: Query retrieving data as number when data type is a varchar with text
Learning Newbie's Avatar
Moderator

Posts: 5,199
Name: John Alexander
Select * is nothing but problems!
__________________
4 ways to improve the lives of the "bottom billion"

"HEY YOU KIDS GET OFF MY LAWN!" -John McCain
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Query retrieving data as number when data type is a varchar with text
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.15032 seconds with 12 queries