SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Addict jasongr's Avatar
    Join Date
    Jul 2004
    Location
    usa
    Posts
    371
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    callback function from MySQL to PHP

    Hello

    I am storing information on people in the database.
    For each person I am storing his address.
    The address may be translated to other languages and it may not.
    If it is translated, this is indicated in the people table with a boolean:
    Code:
    create table `people` (
      `ID` int unsigned not null,
      `First_name` varchar(255) not null,
      `Last_name` varchar(255) not null,
      `Address` varchar(255) not null,
      `Is_Address_translated` tinyint not null,
      PRIMARY KEY  (`ID`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
    If the address is not translated, it should be taken as is from this table. Otherwise, it should be translated first into a specific language.
    I have a code in PHP that knows how to translate a string into a specific language.

    The problem:
    I need to be able to sort the people according to their address.
    If a certain person has a non-translated language, the MySQL server should use the address as is when sorting the data.
    If a certain person has a translated language, the MySQL sever should use the translated address when sorting the data.

    My question:
    Is there a way to utilize my PHP function, by telling MySQL to invoke some callback PHP function when it needs to compare addresses?

    Another solution would be to store the translated addresses in the database (I am trying to avoid this solution if possible)

    regards

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,215
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by jasongr
    Another solution would be to store the translated addresses in the database (I am trying to avoid this solution if possible)
    why are you trying to avoid it?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Addict jasongr's Avatar
    Join Date
    Jul 2004
    Location
    usa
    Posts
    371
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The reason I am trying to avoid it is because translations are much easier to manage outside of the database.

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,215
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    yeah, but you will have to translate it umpteen times (where "umpteen" is a technical term meaning the exact number of times that the data is requested)

    versus translating it once and then simply retrieving it

    in an online application, guess which yields better performance -- instant retrieval of pre-translated data from a slightly larger hard drive, or constant re-translation from a smaller hard drive?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Addict jasongr's Avatar
    Join Date
    Jul 2004
    Location
    usa
    Posts
    371
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I agree that storing the information on the database will be more efficient.
    I am just wondering if the other suggestion was at all possible

  6. #6
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,215
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    yes, it's possible

    i wouldn't do it, though

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  7. #7
    SitePoint Addict jasongr's Avatar
    Join Date
    Jul 2004
    Location
    usa
    Posts
    371
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for the reply

    could you tell me how this can be done?
    preferrably with an example. or otherwise refer me to some manual I could read.
    If, yes, please do (I am anticipating your answer as being a short 'yes')

    regards

  8. #8
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,215
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    i'm sure it's possible, but unfortunately (for you, not for me ) i don't do php
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


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
  •