Jump to content


Photo

News content Help


  • Please log in to reply
2 replies to this topic

#1 maxic0

maxic0
  • Members
  • PipPipPip
  • Advanced Member
  • 70 posts

Posted 12 September 2006 - 05:05 PM

Hi, im creating a page and i want the content to display in boxes on my home page.
I have set up the CSS, and it works fine when i type i the content myself, but when i get the content from my database i have a little probelm.

For testing i created a new content that says "Blah Blah".
Then i looked on my homepage to see if it was displayed..
But instead of it displaying a content box that contains "Blah Blah".
I have two content boxes that both contain "B".

Here is my code..
<?php
include "connect.php";

echo "<DIV ALIGN='center'>";
$result = mysql_fetch_array(mysql_query("SELECT content FROM content"));
foreach ($result as $news_item)
{
   ?>
   <div id="header"></div>
   <div id="content">
   <p>
   <?php
   echo $news_item['content'];
    ?>
    </p>
   </div>
   <div id="footer"></div>
<?php
echo "<BR />";
}
echo "</DIV>";
?>


Im really stuck :-[

Please someone help me!

Thanks
Max

#2 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 12 September 2006 - 05:21 PM

<?php
include "connect.php";

echo "<DIV ALIGN='center'>";
$result = mysql_query("SELECT content FROM content") or die(mysql_error());
while($row = mysql_fetch_array($result))
{
   ?>
   <div id="header"></div>
   <div id="content">
   <p>
   <?php
   echo $row['content'];
    ?>
    </p>
   </div>
   <div id="footer"></div>
<?php
echo "<BR />";
}
echo "</DIV>";
?>

Try that.  You really shouldn't combine all your functions like that.  It makes it a nightmare to troubleshoot.  Also, this is not where you want to use a foreach.

Info: PHP Manual


#3 maxic0

maxic0
  • Members
  • PipPipPip
  • Advanced Member
  • 70 posts

Posted 12 September 2006 - 05:35 PM

Yay it works! Thanks man.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users