Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: readmore link

  1. #1
    Regular Coder
    Join Date
    May 2007
    Location
    Indonesia
    Posts
    164
    Thanks
    10
    Thanked 0 Times in 0 Posts

    readmore link

    Hello,

    I'm trying to figure out how to make a readmore link to show the full length of a message I have worked out the php part by using substr and now want to make it so that when the read more link is clicked the full message will be diplayed on the same page. Can someone help me out? The area I'm having trouble with is the linking part <a href=message_board.php> I'm not sure what to append to the end of the file. I'll post the code to the page I'm working on if need be. I've posted the entire page.

    PHP Code:
    <?php # modified script (sort disabled) - classifieds.php 
    # (modified 12 Jan 2009)

    // This script retrieves all the records from the users table.
    // This new version allows the results to be sorted in different ways.




    require_once ('mysql_connect.php'); // Connect to the db.


    // Number of records to show per page:
    $display 10;

    // Determine how many pages there are. 
    if (isset($_GET['np'])) { // Already been determined.
        
    $num_pages $_GET['np'];
    } else { 
    // Need to determine.

         // Count the number of records
        
    $query "SELECT COUNT(*) FROM entry ORDER BY id ASC";
        
    $result mysql_query ($query);
        
    $row mysql_fetch_array ($resultMYSQL_NUM);
        
    $num_records $row[0];
        
        
    // Calculate the number of pages.
        
    if ($num_records $display) { // More than 1 page.
            
    $num_pages ceil ($num_records/$display);
        } else {
            
    $num_pages 1;
        }
        
    // End of np IF.

    // Determine where in the database to start returning results.
    if (isset($_GET['s'])) {
        
    $start $_GET['s'];
    } else {
        
    $start 0;
    }


            
    // Make the query.
    $query "SELECT * from entry LIMIT $start, $display";        
    $result mysql_query ($query); // Run the query.

    // Fetch and print all the records.


    echo '<center><table style="width:100%; border:1px solid #000000;"><span style="color:#800000;font-size:18px";><center>Affirmation Board</center></span>
    </br>
    <tr><th colspan=\"4\"></th></tr>'
    ;

    while (
    $row mysql_fetch_array($resultMYSQL_ASSOC)) 
    {
        
    $id $row['id'];
        
    $message nl2br(substr($row['message'],0,200));
        
    $name $row['name'];
        
    $date $row['date'];
        
    //$readmore = $row['<a href="#">Readmore</a>'];
    //nl2br(substr($row[post],0,200)). '<br /><br /><br />';

    printf("<tr>

        <td>$message</td>
    <td>
       $name
    </td>
    <td>$date</td>

    <td>
       
    </td></tr><td>  <a href='#'>Readmore</a>   </td>"
    ,  $date$message$name);  



    }

    print 
    '</table></center>';




    mysql_free_result ($result); // Free up the resources.    

    mysql_close(); // Close the database connection.


    // Make the links to other pages, if necessary.
    if ($num_pages 1) {
        
        echo 
    '<center><p>';
        
    // Determine what page the script is on.    
        
    $current_page = ($start/$display) + 1;
        
        
    // If it's not the first page, make a Previous button.
        
    if ($current_page != 1) {
            echo 
    '<a href="message_board.php?s=' . ($start $display) . '&np=' $num_pages '">Previous</a> ';
        }
        
        
    // Make all the numbered pages.
        
    for ($i 1$i <= $num_pages$i++) {
            if (
    $i != $current_page) {
                echo 
    '<a href="message_board.php?s=' . (($display * ($i 1))) . '&np=' $num_pages '">' $i '</a> ';
            } else {
                echo 
    $i ' ';
            }
        }
        
        
    // If it's not the last page, make a Next button.
        
    if ($current_page != $num_pages) {
            echo 
    '<a href="message_board.php?s=' . ($start $display) . '&np=' $num_pages '">Next</a>';
        }
        
        echo 
    '</p>';
        
    // End of links section.




    ?>
    Last edited by rjkdonaldson; 03-10-2010 at 06:40 AM. Reason: added code

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    Try this ...

    PHP Code:
    $id $row['id']; 
        
    // $message = nl2br(substr($row['message'],0,200)); 
        
    $message $row['message']; 
        
    $name $row['name']; 
        
    $date $row['date']; 
        
    //$readmore = $row['<a href="#">Readmore</a>']; 
    //nl2br(substr($row[post],0,200)). '<br /><br /><br />'; 

  • #3
    Regular Coder
    Join Date
    May 2007
    Location
    Indonesia
    Posts
    164
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Wouldn't that return everything within the message table, what I trying to do is limit the view of what can be seen by the user and then when the readmore link is clicked the entire message will be displayed. I remember that my code was originally
    PHP Code:
    $message $row['message']; 
    before adding the substr method.

  • #4
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    oh ... I'm sorry,
    I thought it was the other way around.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •