IT.COM

[Resolved] PHP MYSQL results not displaying

Spaceship Spaceship
Watch

Alex.

Account Closed
Impact
5
PHP MYSQL results not displaying

Hi, on my sites homepage, I've coded it to get the announcements from the DB, then to get the site news and display it afterwards.
The sites announcements work fine, but the news wont display, what am I doing wrong??

index.php:
Code:
<?php /* Created on: 25/02/2007 */
require 'includes/config.php';
//Include the template headers and menu
$config['PAGE_TITLE'] = "Home";
include("template/header.html");
include("template/left.html");
//Get the announcements from the database
$anouncements = "SELECT *, DATE_FORMAT(posted, '%D, %M, %Y') AS d FROM frontpageanouncements ORDER BY id";
$result = mysql_query($anouncements, $dbconn);
$number1 = mysql_num_rows($result);
$number0 = 1;
while ($row = mysql_fetch_array($result)) {
$anounce[$number0]['header'] = "<h3>".$row['title']." <span class=\"date\">".$row['d']." // Posted by ". $row['author']."</span></h3>\n\n"; 
$anounce[$number0]['content'] = "<p>".$row['anouncement']."</p>"; 
$number0 ++;
} 

//Get the news from the database
$newsq = "SELECT *, DATE_FORMAT(posted, '%D, %M, %Y') AS d FROM news ORDER BY nid";
$result2 = mysql_query($newsq, $dbconn);
$number2 = mysql_num_rows($result2);
$number3 = 1;	
while($row = mysql_fetch_array($result)) {
		$news[$number3]['header'] = "<h3>".$row['title']." <span class=\"date\">".$row['d']." // Posted by ". $row['author']."</span></h3>\n\n"; 
		$news[$number3]['content'] = "<p>".$row['news']."</p>"; 
		$number3 ++;}
		 









?> 


<?php for ($i = 1; $i <= $number1; $i++) {
   echo $anounce[$i]['header'];
   echo $anounce[$i]['content'];
}
?>
			 

<h3>News</h3>
<h3>This is a Header <span class="date">12.06.06 // Comments (1)</span></h3>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Integer euismod ante non diam. Sed eleifend odio sed quam. Sed vulputate, turpis at tincidunt porttitor, est elit consequat metus, non dignissim augue mauris quis arcu. Phasellus faucibus blandit eros. Curabitur porttitor ante non est. Maecenas dolor. Aenean egestas sem. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos hymenaeos. Sed suscipit, nisi sit amet pharetra malesuada, sem velit laoreet sem, vitae iaculis diam neque consequat est. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Pellentesque tincidunt eros non quam. Mauris a magna sit amet libero accumsan auctor.</p>   
<?php 

 for ($i = 1; $i <= $number2; $i++) {
   echo $news[$i]['header'];
   echo $news[$i]['content'];
}
?>


<?php include("template/footer.html");?>

Thanks in advance :)
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
You have:

PHP:
//Get the news from the database
$newsq = "SELECT *, DATE_FORMAT(posted, '%D, %M, %Y') AS d FROM news ORDER BY nid";
$result2 = mysql_query($newsq, $dbconn);
$number2 = mysql_num_rows($result2);
$number3 = 1;	
while($row = mysql_fetch_array($result)) {
		$news[$number3]['header'] = "<h3>".$row['title']." <span class=\"date\">".$row['d']." // Posted by ". $row['author']."</span></h3>\n\n"; 
		$news[$number3]['content'] = "<p>".$row['news']."</p>"; 
		$number3 ++;}
replace:
PHP:
while($row = mysql_fetch_array($result)) {
with:
PHP:
while($row = mysql_fetch_array($result2)) {

in essence, replace $result with $result.
 
1
•••
Thank you so much :)

Rep++ added :D
 
0
•••
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back