Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

MySQL/HTML quickie...

  • 25-09-2006 12:00AM
    #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,890 ✭✭✭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