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

PHP question

  • 04-04-2005 6: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,281 ✭✭✭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