SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot websalacarta's Avatar
    Join Date
    May 2003
    Location
    Spain
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    problem with SUBSTRING_INDEX

    Hi,

    I have this query:

    Code:
    SELECT empresas.nombre, SUBSTRING_INDEX( empresas.descripcion, ' ', 40 )
    FROM destacados
    LEFT JOIN empresas ON destacados.id_reg = empresas.id
    WHERE destacados.estado =2
    That query works correclty in phpmyadmin, but when I execute that in my code (php) that doesn´t work

    when I delete SUBSTRING_INDEX, the query works correctly in both, phpmyadmin and in my code

    I´m using the same database for phpmyadmin and for my code, so... I don´t understand anything

    anybody know what can be the problem?

    thanks

  2. #2
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Örebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I do not know if this is what is causing it, but try assigning the value to an alias:

    Code:
    SUBSTRING_INDEX( empresas.descripcion, ' ', 40 ) AS substring_result
    Yours, Erik.
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,347
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    what does "doesn't work" mean? are you getting a syntax error?

    what did you want SUBSTRING_INDEX to return? the first 40 words, right?
    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
  •