FRIHOSTFORUMSSEARCHFAQTOSBLOGSCOMPETITIONS
You are invited to Log in or Register a free Frihost Account!


News system





DanielXP
Im trying to remake my user system heres the code.

Code:
<?
   function display_news() {
   $news = NULL;
   $get_news = mysql_query("SELECT * FROM `news` ORDER BY `id` DESC LIMIT 5");
   $number_off_news = mysql_num_rows($get_news);
   if($number_off_news == "0") {
   $news .= "<td><table height='5' width='100%' cellpadding='5'><tr><td>
         <table width='80%' bgcolor='#F2C6C6' style='border:1px solid #B33625'>
         <tr>
         <td><b>Error:</b><br>There is currently no news in the database.</td>
         </tr>
         </table>
         </td></tr></table></td>";   
   }else{
   while($news = mysql_fetch_array($get_news)) {
   $news .= "<td class=\"subheader\">Posted by ..........</td>";
   }
   }
      echo $news;
   }
?>


Thats my display_news.php page.

If there is nothing in the database it comes up the error message saying it.

But if there is news in the database it does not display any thing?!?

If put in
Code:
echo "Testing...";
under
Code:
   $news .= "<td class=\"subheader\">Posted by ..........</td>";
   }
So that means it is going to the else but the while is not working.

Please help.

Thanks
Daniel
alalex
you should put the echo $news into the while loop, thiw way:
Code:
while($news = mysql_fetch_array($get_news)) {
   $news .= "<td class=\"subheader\">Posted by ..........</td>";
   echo $news;
 }
qscomputing
You could also indent your code properly so you can see exactly what you're looking at - one more tab (or 2 more spaces) every time you enter braces.

I learnt to do this the hard way (came to read some non-indented code that I'd written and gave up), I think most people probably do.
DanielXP
alalex wrote:
you should put the echo $news into the while loop, thiw way:
Code:
while($news = mysql_fetch_array($get_news)) {
   $news .= "<td class=\"subheader\">Posted by ..........</td>";
   echo $news;
 }


I tryed echoing out inside the while and nothing came out.

qscomputing wrote:
You could also indent your code properly so you can see exactly what you're looking at - one more tab (or 2 more spaces) every time you enter braces.

I learnt to do this the hard way (came to read some non-indented code that I'd written and gave up), I think most people probably do.


I don't know how to indent
DanielXP
Got it working.

Please lock
Related topics
Coranto - News system
News system with mySQL database.
Problem installing a news system
I need a open source news system .
news system with login for more than 1 user.
Want a news script which doesnt use MySQL?
[news].[tecg]Últimas Vulnerabilidades
[Community Project] Easy Simple Content Management System
Next\previous button on news system
News script
Azkabanweb.tk
Web design
Which is the best content management software
Which scripts are the most useful to learn?
This topic is locked: you cannot edit posts or make replies.    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.