Jump to content

Displaying results


john010117

Recommended Posts

Hello.
I have this code:

[code=php:0]
<?php
 
  // Connection information
  $db_host = "localhost";
  $db_user = "**";
  $db_pass = "**";
  $db_name = "**";
 
  // Connect to server
  $dbac = mysql_connect($db_host,$db_user,$db_pass);
  $today = getdate();
 
  // Select database
  mysql_select_db ($db_name) or die ("Cannot connect to database");
 
  // Get date from _GET param or current date if not available
  $_GET['date'] = @trim(stripslashes($_GET['date']));
  $date = ($_GET['date'] && !empty($_GET['date'])) ? date('Y-m-d', strtotime(trim($_GET['date']))) : date('Y-m-d');
 
  $result = mysql_query('SELECT * FROM news WHERE Date = "' . $date . '" ORDER BY Time');
  $curtime = time();
  if ($result && mysql_num_rows($result)) {
    $numrows = mysql_num_rows($result);
    $rowcount = 1;
   
    while ($row = mysql_fetch_assoc($result)) {
     
      while(list($var, $val) = each($row)) {
        extract ($row);
        print "<b>$Title</b><br />$News<br /><font size='2'>$Date &nbsp; $Time</font><br />";
      }
     
      print "<br />";
      ++$rowcount;
    }
  }
 
?> 
[/code]

I have a table (called news) in a MySQL database with 5 fields: (News, Title, Date, Time). The code works. However, when I display the results, it shows the same thing 5 times.

This is what shows:

[quote]
[b]News system up and running![/b]
We finally have this news system working. If you want to see older news (by date), just click the arrow on top.
2007-01-12 13:12:42

[b]News system up and running![/b]
We finally have this news system working. If you want to see older news (by date), just click the arrow on top.
2007-01-12 13:12:42

[b]News system up and running![/b]
We finally have this news system working. If you want to see older news (by date), just click the arrow on top.
2007-01-12 13:12:42

[b]News system up and running![/b]
We finally have this news system working. If you want to see older news (by date), just click the arrow on top.
2007-01-12 13:12:42

[b]News system up and running![/b]
We finally have this news system working. If you want to see older news (by date), just click the arrow on top.
2007-01-12 13:12:42
[/quote]

How can I make it so that it only shows a news post ONCE?

PS: I think it's because of the extract($row) thing.
Link to comment
Share on other sites

Your mkaing it a little more complicated then need be.

[code=php:0]
while ($row = mysql_fetch_assoc($result)) {
  print "<b>{$row['$Title']}</b><br />{$row['News']}<br /><font size='2'>{$row['Date']} &nbsp; {$row['Time']}</font><br /><br />";
}
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.