Jump to content

[SOLVED] Need some help grabbing from mySQL


darklight

Recommended Posts

This keeps returning nothing back...

 

$getnews = mysql_query("SELECT * FROM `news` ORDER by id");
		 $newsnum = mysql_num_rows($getnews);
		 if ($newsnum <= 0) { 
                echo ("There is no news at the moment."); 
                } 
			else
                {
			$news = mysql_fetch_array($getnews); 
			while ($news = mysql_fetch_array($getnews)) 
               { 
            echo "
		<center>
		<table width=\"550\" border=\"1\" cellspacing=\"0\" cellpadding=\"1\">
             <caption>
               Date: $news[date]
             </caption>
           <tr>
       <td>$news[content]</td>
   </tr>
</table>
</center>";

Can't even read that Im afraid. Lets format it so its readable and add some debugging.

 

<?php

  $sql = "SELECT * FROM `news` ORDER by id";
  if ($result = mysql_query($sql)) {
    if (!mysql_num_rows($result)) { 
      echo "There is no news at the moment."; 
    } else { 
      while ($news = mysql_fetch_array($result)) { 
        echo "
          <center>
            <table width=\"550\" border=\"1\" cellspacing=\"0\" cellpadding=\"1\">
              <caption>
                Date: {$news['date']}
             </caption>
             <tr>
               <td>{$news['content']}</td>
             </tr>
           </table>
         </center>";
      }
    }
  } else {
    echo mysql_error() . "<br />$sql";
  }

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.