Jump to content

[SOLVED] News Problem


Nexy

Recommended Posts

Why Hello There!  :) I seem to be having a problem with a script I made to show news.

 

<?php
        $usern = "SELECT user FROM news ORDER BY id DESC";
$userres = mysql_query($usern) OR die(mysql_error());

$avan = "SELECT avatar FROM news ORDER BY id DESC";
$avares = mysql_query($avan) OR die(mysql_error());

$titlen = "SELECT subject FROM news ORDER BY id DESC";
$titleres = mysql_query($titlen) OR die(mysql_error());

$daten = "SELECT date FROM news ORDER BY id DESC";
$dateres = mysql_query($daten) OR die(mysql_error());

$newn = "SELECT news FROM news ORDER BY id DESC";
$newsres = mysql_query($newn) OR die(mysql_error());



while($pic = mysql_fetch_array($avares))
   while($title = mysql_fetch_array($titleres))
                    while($use = mysql_fetch_array($userres))
         while($date = mysql_fetch_array($dateres))
            while($news = mysql_fetch_array($newsres))
{

echo "<div id='nstaff'>
       		<p class='avatar'>";

echo "<img src='";

	echo $pic['avatar'];

echo "' alt='' class='tinyav' /></p>";
echo "<div id='nstaffcont'>";

	echo "<p id='title'>" . $title['subject'] . '</p>';
	echo "<p id='user'>By: " . $use['user'] . '<br />';
	echo "Posted On: " . $date['date'] . '</p>';

	echo "<p id='news'>" . $news['news'] . '</p>';

echo "</div></div>";

}
?>

 

It's probably not the best way to do it, but it's the only way I know how. There are a few problems:

 

1. If I post more then 1 news with different content, it doesn't show the old news title, username, or date. But the actual news shows differently.

2. If I was to post from a different account, it will overwrite each news post with that person's username, avatar, title, date, etc...

 

You can see it here: http://divnx.net

 

The bottom news post was suppose to say "Working on news script" for title. "Nexy" for "Posted By:" and 5-31-08. As you can see it was taken over by Sekai's latest Title, date, and username.

 

Hope someone can help me. Thank You!  :)

 

P.S. In the database, everything is the way it should be. The Title, Date, Username, Avatar, and News are all different.

Link to comment
https://forums.phpfreaks.com/topic/108307-solved-news-problem/
Share on other sites

You only need one query, try this

 

<?php

        $usern = "SELECT user, avatar, subject, date, news FROM news ORDER BY id DESC";
$userres = mysql_query($usern) OR die(mysql_error());


while($row = mysql_fetch_array($usern)){

echo "<div id='nstaff'>
       		<p class='avatar'>";

echo "<img src='";

	echo $row['avatar'];

echo "' alt='' class='tinyav' /></p>";
echo "<div id='nstaffcont'>";

	echo "<p id='title'>" . $row['subject'] . '</p>';
	echo "<p id='user'>By: " . $row['user'] . '<br />';
	echo "Posted On: " . $row['date'] . '</p>';

	echo "<p id='news'>" . $row['news'] . '</p>';

echo "</div></div>";

}
?>

Link to comment
https://forums.phpfreaks.com/topic/108307-solved-news-problem/#findComment-555274
Share on other sites

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.