SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    blonde.... Sarah's Avatar
    Join Date
    Jul 2001
    Location
    Berkshire, UK
    Posts
    7,442
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    select staement but only reading 100 characters of answer...

    This is my select query, I want to only see an abstract of the col news_text (you'll be able to click on more... if you want to see more) BUT I get nothing? I do remember this not liking when I checked from Kev's book but didn't take much notice... anybody spot my error?

    $result= "SELECT nid, news_title, left(news_text,100), news_image FROM news where news.cid=1";

    Thanks

    Sarah
    Regular user

  2. #2
    Custom User Title v1.0 FireFly's Avatar
    Join Date
    Aug 2001
    Posts
    363
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try giving it an alias, like this:
    Code:
    $result= "SELECT nid, news_title, LEFT(news_text,100) AS shortnews, news_image FROM news where news.cid=1";
    then use $row['shortnews'] in your script.

  3. #3
    blonde.... Sarah's Avatar
    Join Date
    Jul 2001
    Location
    Berkshire, UK
    Posts
    7,442
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks!!

    That worked a treat - suppose should have cottoned onto that one...

    Thanks

    Sarah
    Regular user

  4. #4
    SitePoint Evangelist =X='s Avatar
    Join Date
    Jun 2001
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    from mysql manual

    LEFT(str,len)
    Returns the leftmost len characters from the string str:

    mysql> select LEFT('foobarbar', 5);
    -> 'fooba'


    This function is multi-byte safe.
    PHP-Webservices - Profesional Hosting and Programming of sites.

  5. #5
    blonde.... Sarah's Avatar
    Join Date
    Jul 2001
    Location
    Berkshire, UK
    Posts
    7,442
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    =X=

    I understand that, the part I wasn't getting was to use as aliase to call later on!!
    Regular user

  6. #6
    SitePoint Evangelist =X='s Avatar
    Join Date
    Jun 2001
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh sorry, I didn't see there already was a reply

    I just got this out of the manual to show that there was nothing wrong with that part
    PHP-Webservices - Profesional Hosting and Programming of sites.

  7. #7
    blonde.... Sarah's Avatar
    Join Date
    Jul 2001
    Location
    Berkshire, UK
    Posts
    7,442
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    thats cool that was what was confusing me also... but thanks to firefly we now know if you use a LEFT(...) then to include an aliase if you need to use that variable later on...
    Regular user

  8. #8
    Custom User Title v1.0 FireFly's Avatar
    Join Date
    Aug 2001
    Posts
    363
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's not only when you do LEFT() on a column, it's pretty much whenever you use a function on one. (Because you can't use $row['IF(bday=today,1,0)'] in PHP, you must give it an alias as well )

  9. #9
    blonde.... Sarah's Avatar
    Join Date
    Jul 2001
    Location
    Berkshire, UK
    Posts
    7,442
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I suppose once learned never forgotten - cheers
    Regular user


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
  •