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 6 of 6
  1. #1
    New Coder
    Join Date
    Jun 2005
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Displaying Articles on a Single Dynamic Page

    Ok, here is what i want to do. Im making a pc news website right, and i've set up the index to show the header (a brief description of the article) of the last 6 articles and that works fine. Now, what i want is this. I want 1 page, that displays 1 article at a time. So, at the end of my headers, i put a (read more) link (like so http://www.siliconjunkie.com.au). I want the (read more) link to link to the article (displaying the whole body of the article aswell. I want the article be displayed on a page which i;ve named article.php. Now how do i do this. I know that the article id or soemthing will probably be in the url. So, kind of what anantech does (excpet they dotn ahve a read more link, they just use the heading as a link.

    Here's a link to 2 pages that you can look at and manipulate to make this work.

    http://files.siliconjunkie.com.au/files/phpfiles.zip

    Anyhelp will be greatly appreciated...

    Cheers!
    Last edited by Sloth_Boy; 09-12-2005 at 11:37 AM.

  • #2
    Regular Coder
    Join Date
    Jan 2005
    Posts
    153
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You are grabbing that from mysql? If so, here's a basic retrieval method that i use to get a certain amount of text, and then show a read more... link that links to the article. If you don't have these rows, make something like them (id is a mediumint( 8 ) UNSIGNED NOT NULL AUTO_INCREMENT; date is a DATE NOT NULL, pulled out with a specified format with DATE FORMAT). You can use the code below if you want and make any changes necessary to make it work for you!
    PHP Code:
    <?PHP
    //mysql_connect/mysql_select_db/etc.
    //again feel free to edit and have fun with this code all you like to make it work for you!
    $id $HTTP_GET_VARS['id'];
    if(!isset(
    $id) || empty($id))
    {
        
    $id mysql_real_escape_string($id);
        
    $sql 'SELECT id,title,MID(content,1,50) AS content,DATE_FORMAT(date, \'%d/%m/%Y\') AS date FROM news ORDER BY id DESC LIMIT 6';
        
    $result mysql_query($sql) or die('Could not gather news items from database');
        while(
    $row mysql_fetch_object($result))
        {
            echo 
    '<fieldset><legend>' $row->title ' - ' $row->date '</legend>' $row->content '<BR /><a href="?id=' $row->id '">(full story)</a></fieldset>';
        }
    }
    else
    {
        
    $id mysql_real_escape_string($id);
        
    $sql 'SELECT id,title,content,DATE_FORMAT(date, \'%d/%m/%Y\') AS date FROM news WHERE id = \'' $id '\'';
        
    $result mysql_query($sql) or die('Could not gather single news item from database. Check id and try again.');
        
    $row mysql_fetch_object(result);
        echo 
    '<fieldset><legend>' $row->title ' - ' $row->date '</legend>' $row->content '</fieldset>';
    }
    ?>
    NOTE: I haven't checked this on a server yet, but unless there's a typo in it, in theory, it should do what you need.

    Of course, it wouldn't be too hard to show the (full story) link only if the article had less than fifty characters. Just make a strlen on $row->content, and if it is less than 50, make $content = $row->content . '<BR /><a herf="...">(read more)</a>'; and if not, then $content = $row->content; Then you just replace $row->content in the echo with $content and you're done!

    Hope I helped!
    -Yaggles

  • #3
    New Coder
    Join Date
    Jun 2005
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts
    does that code go on the display page or the (read more) page?

  • #4
    New Coder
    Join Date
    Jun 2005
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Could you (or someone else) possibly add that into my files (link in original post), that way i can learn and understand it alot better.

    Cheers
    Last edited by Sloth_Boy; 09-12-2005 at 02:14 PM.

  • #5
    New Coder
    Join Date
    Jun 2005
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Please, could someone please do that for me...

  • #6
    Regular Coder
    Join Date
    Jan 2005
    Posts
    153
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You don't need a "read more" file... just use that one. It'll do the "read more" part if there's a value set for ?id= in the URI.

    I may be able to add it for you later, but I'm kinda busy now.


  •  

    Posting Permissions

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