[SOLVED] News script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
haym37
Forum Newbie
Posts: 2
Joined: Sat Jun 26, 2004 10:03 am

[SOLVED] News script

Post by haym37 »

I am making a simple news script for staff to post news on my website. I have already made the login part which works perfectly. Now, for the news, when I go to post something it stores it in the MySQL database perfectly. But, when I have to display it, this is where I get the problem. It only displays the most recent news I posted, but I want it to display all of the news. This is my code for displaying the news:

Code: Select all

<?php

// Copyright: haym37

require 'config.php';

$link = mysql_connect("$dbhost", "$dbuser", "$dbpass") or die("Could not connect to database: " . mysql_error()); 

mysql_select_db("$dbdatabase") or die("Could not select database: " . mysql_error());


$result = mysql_query("SELECT * FROM news LIMIT 30");
$newsinfo = mysql_fetch_array($result);
extract($newsinfo);

echo "<br>
<table width='75%' border='1' align='center' bordercolor='#000000' bgcolor='#FFFFFF'>
<tr>
    <td><div align='center'><font color='#000000' size='2' face='Verdana, Arial, Helvetica, sans-serif'>On 
        <b>$date</b>, <b>$author</b> posted <b>$title</b></font></div></td>
  </tr>
  <tr>
    <td><div align='center'><font color='#000000' size='3' face='Verdana, Arial, Helvetica, sans-serif'>$news</font></div></td>
  </tr>
</table>
<br>";

mysql_close($link);

?>

If you could somehow help me display all of the news that I posted, that would be great. I even tried echoing it twice, but it displays the same news twice. Any help would be great. Thanks!


feyd | added

Code: Select all

tags :: [/color][url=http://forums.devnetwork.net/viewtopic.php?t=21171][color=red]:arrow: [u][b]Posting Code in the Forums[/b][/u][/color][/url]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

<?php

$result = mysql_query("SELECT * FROM news LIMIT 30"); 
while($newsinfo = mysql_fetch_assoc($result))
{
extract($newsinfo); 

echo "<br> 
<table width='75%' border='1' align='center' bordercolor='#000000' bgcolor='#FFFFFF'> 
<tr> 
    <td><div align='center'><font color='#000000' size='2' face='Verdana, Arial, Helvetica, sans-serif'>On 
        <b>$date</b>, <b>$author</b> posted <b>$title</b></font></div></td> 
  </tr> 
  <tr> 
    <td><div align='center'><font color='#000000' size='3' face='Verdana, Arial, Helvetica, sans-serif'>$news</font></div></td> 
  </tr> 
</table> 
<br>"; 
}

?>
try that.
haym37
Forum Newbie
Posts: 2
Joined: Sat Jun 26, 2004 10:03 am

Post by haym37 »

Thanks feyd! It works!!! Once again, thanks a lot!
Post Reply