john010117 Posted January 12, 2007 Share Posted January 12, 2007 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 $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. Quote Link to comment Share on other sites More sharing options...
trq Posted January 12, 2007 Share Posted January 12, 2007 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']} {$row['Time']}</font><br /><br />"; }[/code] Quote Link to comment Share on other sites More sharing options...
john010117 Posted January 12, 2007 Author Share Posted January 12, 2007 Ok, thank you. It's working. :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.