SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Zealot
    Join Date
    Apr 2006
    Location
    Manchester; UK
    Posts
    158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Displaying Data Problem (MySQL)

    Hey,

    I have coded a news Content Management Syste but I am having some problems showing the data in my MySQL Database, it is adding into the database easily enough but it just won't display, I am a bit of a newbie at PHP so sorry if it is a simple answer:

    Here is the code:

    PHP Code:
    <?php

    // Dan Williamson
    // Display The News


    // Connect to the MySQL Database

    require('dbconnect.php');

    // Statements

    if($_GET['action'] =="view") {

    // Display Result

    $id $_GET['id'];

    // MySQL Query

    $query "SELECT * FROM news ORDER BY ID DESC LIMIT 5";

    // Excecute Query

    $result mysql_query($query) or die(mysql_error());

    // Display Query Results

    while ($row mysql_fetch_array($result)) {

    // mysql_fetch fetching $result

    extract($row);

    $content nl2br($content);

    // Echo the stuff

    echo "<p><b>$title</b></p><p>$author</p><p>$date</p><br /><br /><p>$content</p>";
    }
    } else {

    // Display
    // List

    }


    mysql_close($connection);

    ?>
    I have heavily commented the code for myself so you should be able to use that.

    It isn't coming up any error, but it is just being blank. http://dan-williamson.co.uk/news/news.php

    Thanks for any help,
    Dan Williamson

  2. #2
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,001
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    while ($row mysql_fetch_assoc($result)) { 
    echo 
    "<p><b>".$row["title"]."</b></p><p>".$row["author"]."</p><p>".$row["date"]."</p><br /><br /><p>".$row["content"]."</p>";

    -- Jelena --

  3. #3
    SitePoint Zealot
    Join Date
    Apr 2006
    Location
    Manchester; UK
    Posts
    158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That didn't seem to work :s Thanks for the reply and the try though!

  4. #4
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,001
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Do you meet the condition if($_GET['action'] =="view") ?
    -- Jelena --

  5. #5
    SitePoint Zealot
    Join Date
    Apr 2006
    Location
    Manchester; UK
    Posts
    158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have no idea what that means i'm afraid.

  6. #6
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,001
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Could you please do
    PHP Code:
    var_dump($_GET["action"]); 
    Somewhere before that 'if'?
    -- Jelena --

  7. #7
    SitePoint Zealot
    Join Date
    Apr 2006
    Location
    Manchester; UK
    Posts
    158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I did that, it displays 'NULL' yet I have a few little test things in my DB

  8. #8
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,001
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    So, that means that condition if($_GET['action'] =="view") isn't true and query doesn't get executed. Else part is executed and you don't do in else anything.
    -- Jelena --

  9. #9
    SitePoint Zealot
    Join Date
    Apr 2006
    Location
    Manchester; UK
    Posts
    158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, I solved it with a simple re-coding of some parts


Bookmarks

Posting Permissions

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