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: News Script

  1. #1
    New to the CF scene
    Join Date
    Jun 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    News Script

    Hi there, I am fairly new to PHP and am looking for some help.

    I have written a basic news script so that myself and others can add news to the site throught the browser, however at the moment the full news for each article is displayed on the home page, I am looking to make it so that the headline only is displayed and then visitors click on that to read the full article.

    I have a news.php file which displays the headlines, when you click on the name of the news article it loads viewArticle.php for that news item, however when it loads this all I see is the line Posted by:

    I have attached the code for both pages, I am lost as to where I am going wrong and any help would be much appreciated.

    news.php

    Code:
    <?php
    include ('mysql_connect.php');
    $query = "SELECT id,title,author,post, DATE_FORMAT(date, '%M %d, %Y') as sd FROM news_data";
    $result = @mysql_query($query);
    
    if ($result) {
    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    $url = 'comments.php?id='.$row['id'];
    echo '<p> <a href="viewArticle.php?id='.$row['id'].'">';
    echo $row['title'];
    echo '</a></p>';
    }
    } else {
    echo 'There are no news posts to display';
    }
    ?>
    viewArticle.php

    Code:
    <?php
    include ('mysql_connect.php');
    
    if(is_numeric($_GET["id"])) {
       $id = $_GET["id"];
    }
    
    if(isset($id)) {
       $query = mysql_query("SELECT * FROM news_data WHERE id = '{id}'")or die(mysql_error());
       $row = mysql_fetch_assoc($query);
    
       echo '<h1>'.$row['title'].'</h1>
    
    '.$row['sd'].'
    
    Posted by : '.$row['author'].'
    
    '.$row['post'].'
    
    </p>';
    }
    
    
    ?>
    I look forward to reading your advice

    Thanks

    Dazz

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    WHERE id = '{id}'
    id is not being parsed, just change it to WHERE id = $id and it will work.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #3
    New to the CF scene
    Join Date
    Jun 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Works fine now, thanks a lot for your help, knew it would be something obvious.

    Cheers again

    Now I can move on to my next task categories

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Good to hear it worked out
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    Posting Permissions

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