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.

PHP question

  • 04-04-2005 07:21PM
    #1
    Closed Accounts Posts: 334 ✭✭


    Hi,

    I am doing a website where news articles are displayed. I want the user to be able to see the first few lines of the article and be able to click on Read More to view the remainder (similar to any of the online newspapers).

    The way I have it at the moment, the headline appears, and the user can click to read more, but I would also like the first few lines to be displayed.
    Has anyone any idea how I can do this?

    Cheers.
    $pages_sql = 'select * from pages order by code';
    $pages_result = mysql_query($pages_sql, $conn);
    
    while ($pages = mysql_fetch_array($pages_result)) {
    
      $story_sql = "select * from stories
                    where page = '".$pages['code']."';
      $story_result = mysql_query($story_sql, $conn);
      if (mysql_num_rows($story_result)) {
        $story = mysql_fetch_array($story_result);
        print '<table border="0" width="400">';
        print '<tr>';
        print '<td>';
        print '<h3>'.$pages['description'].'</h3>';
        print $story['headline'];
        print '</td>';
        print '</tr>';
        print '<tr><td align="right">';
        print '<a href="page.php?page='.$pages['code'].'">';
        print '<font size="1">Read more '.$pages['code'].' ...</font>';
        print '</a>';
        print '</table>';
      }
    


Comments

  • Registered Users, Registered Users 2 Posts: 9,453 ✭✭✭RobertFoster


    Hi,

    I've something similar; it takes the first 100 characters:

    [php]//get message text from database
    $said=stripslashes($row["content"]);
    //first replace <br>'s - make into a single long line
    $said = str_replace("<br>", " ", $said);
    //THEN take tags out - eg smilie <img> tags and so on
    $said=strip_tags($said);
    //if too large
    if (strlen($said)>100){
    $said=substr($said, 0, 100);
    //remove trailing spaces
    $said - rtrim($said);
    }[/php]
    Adjust the 100 to get the desired length.

    Then just echo $said.


  • Closed Accounts Posts: 334 ✭✭WhatsGoingOn


    Hi,

    I've something similar; it takes the first 100 characters:

    [php]//get message text from database
    $said=stripslashes($row["content"]);
    //first replace <br>'s - make into a single long line
    $said = str_replace("<br>", " ", $said);
    //THEN take tags out - eg smilie <img> tags and so on
    $said=strip_tags($said);
    //if too large
    if (strlen($said)>100){
    $said=substr($said, 0, 100);
    //remove trailing spaces
    $said - rtrim($said);
    }[/php]
    Adjust the 100 to get the desired length.

    Then just echo $said.


    Perfect, thanks Robert :D


Advertisement