Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

MySQL/HTML quickie...

  • 24-09-2006 11:00pm
    #1
    Closed Accounts Posts: 8,866 ✭✭✭


    Hi guys, not sure which way this will work. Basically im selecting a bunch of text from a db and I want to know how I can limit the amout of text actually displayed? So for example, if the database contained the text "The quick fox jumped over the lazy dog" I just want to print out "The quick fox jumped...". Is there a way to do it in the sql query or is it html based? In other words, do I limit it here:

    [PHP]$SQL="SELECT * FROM tbl_news";[/PHP]

    Or here:

    [PHP]print($row);[/PHP]

    ??

    Thanks guys!


Comments

  • Closed Accounts Posts: 119 ✭✭frodo_dcu


    Hi guys, not sure which way this will work. Basically im selecting a bunch of text from a db and I want to know how I can limit the amout of text actually displayed? So for example, if the database contained the text "The quick fox jumped over the lazy dog" I just want to print out "The quick fox jumped...". Is there a way to do it in the sql query or is it html based? In other words, do I limit it here:

    [php]$SQL="SELECT * FROM tbl_news";[/php]
    Or here:

    [php]print($row);[/php]
    ??

    Thanks guys!

    The way i do it is php based but imagin it could be done with mySql

    [PHP]$max = 25;
    $text = $row;
    $text_short= substr($text, 0, $max)."...";

    print $text_short;[/PHP]


    this removes all characters after the 25th one or what ever you set $max too and adds ... to the end


  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    Thats perfect, cheers mate!


  • Registered Users, Registered Users 2 Posts: 3,889 ✭✭✭cgarvey


    Doing it in SQL might be more efficient.. something like
    SELECT id, colA, colB, LEFT( news_content, 25 ) FROM tbl_news
    
    should do the trick.


  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    Appreciate that cgarvey, its always good to learn, I'll try it too!


Advertisement