SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jun 2001
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Case Sensitivity in php

    I am working with two tables having the same field names. But in one table, the names are in CAPITALS LETTERS and in the other table the field names are in small letters.

    I want to use the same the code for accessing both the tables as the field names are same. But since php variables are case sensitive I can't use the same code.

    For example, $row["USERNAME"] is not the same as $row["username"].

    Is there some way, I can achieve this in php. This was possible in ASP as the variables are not case sensitive.

    Thanks

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well field names are not case sensitive in MySQL, I think they may be in other true RDBMS servers, but for MySQL you can simply do this

    SELECT USERNAME as username, NEXTFIELD as nextfield from tablename

    Whether USERNAME or NEXTFIELD were uppercase or lowercase you can still select them in either UPPERCASE or lowercase, so by always selecting them as UPPERCAE and assigning them a lowercase alias you will always get your array elements in lowercase so whether you ran this query on table 1 or table 2 you would still get $row["username"]
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    What's HTML?
    Join Date
    May 2001
    Location
    San Diego, CA
    Posts
    1,701
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also if you refer to a table in uppercase and lowercase in the same query, it won't work.

    But to access similar fields from different tables, you can either create an alias (as previously stated) or refer to them like this:
    SELECT table1.userID, table2.userID FROM table1, table2 WHERE table1.userID=table2.userID

    Notice the dot following the table and before the field name. This works with databases too: database.table.field
    Ryan Kuhle - A Proud Advisor - Got Questions? Just Ask!
    Get your website started for less than $20! Click Here

  4. #4
    SitePoint Member
    Join Date
    Jun 2001
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanx guys

    I really appreciate the help. It saved me a lot of headache..


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •