Advice on a table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jbradly
    New Member
    • Mar 2008
    • 13

    Advice on a table

    I want to create a table to which 3 different users will post data. The data is just message/news data and each user will only need to post data to one field. So far I have a table with the fields:
    ID, Message, Daily_Announcem ent, and News

    I want to extract the data posted into each field and display it on a corresponding html page. I have the following code to extract and display the data but it displays everything input into the table and I want to be able to display just the most recent entry from each of the fields. What would be the best way to set up the table and what am I missing to just extract the most recent posting?
    <?php
    $db = mysqli_connect( "localhost" , "", "","db-jvadmin");
    if (!$db)
    {
    die('Could not connect: ' . mysqli_error()) ;
    }

    $query = "SELECT * FROM Announcements";

    $result = mysqli_query($d b,$query);

    while($row = mysqli_fetch_ar ray($result))
    {
    echo $row[Message'];
    }
    mysqli_close($d b);
    ?>
  • TheServant
    Recognized Expert Top Contributor
    • Feb 2008
    • 1168

    #2
    Syntax error: echo $row['Message']; (you had: echo $row[Message'];)

    I will have to think about how to get the most recent as I am still unsure about how the table is set out. Try fix that syntax error and see if it no longer returns all the row data.

    Also post your code in the correct tags! Just above where you post (where the Bold and Italic options are) there are code tags (CODE, PHP, HTML, etc).

    Comment

    • Markus
      Recognized Expert Expert
      • Jun 2007
      • 6092

      #3
      Use a 'limit' clause.

      [php]
      <?php
      $db = mysqli_connect( "localhost" , "", "","db-jvadmin");
      if (!$db)
      {
      die('Could not connect: ' . mysqli_error()) ;
      }

      $query = "SELECT `Message`,`Dail y_Announcement` ,`News` FROM Announcements LIMIT 1";

      $result = mysqli_query($d b,$query);

      while($row = mysqli_fetch_ar ray($result))
      {
      echo "{$row['Message']} - {$row['Daily_Announce ment']} - {$row['News']}";
      }
      mysqli_close($d b);
      ?>
      [/php]
      regards.

      Comment

      Working...