Nexy Posted June 2, 2008 Share Posted June 2, 2008 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. Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted June 2, 2008 Share Posted June 2, 2008 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>"; } ?> Quote Link to comment Share on other sites More sharing options...
Nexy Posted June 2, 2008 Author Share Posted June 2, 2008 Thank You! But you made one little mistake: while($row = mysql_fetch_array($usern)) $usern should have been $userres. But that's ok, thank you for helping, everything works perfectly now! Cheers, NexY Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.