Shoutbox

I need PHP/MySQL help again - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: I need PHP/MySQL help again (/showthread.php?tid=38023)

I need PHP/MySQL help again by matty on 02-07-2005 at 12:18 AM

[Image: attachment.php?pid=376033]
Above is a picture of the mysql database.

What I am trying to do is print out each entry in order according to the NewsNum. The while statement I am using just prints out each row from the first in the image to the last.

code:
$i=0;
while ($i > $num) {
    //Print out news entries
    $i++;
}

If anyone can come up with a better way to do it please let me know.

code:
$i=$num-1;
while ($i >= 0) {
    $j=0;
    while ($j != mysql_result($result,$i,"NewsNum")){
        $j++;
    }
    echo ("<table border='0' width='421' id='table1' cellspacing='0' cellpadding='0'><tr><td width='2%' rowspan='2' background='images/border.gif'>&nbsp;</td><td width='2%' rowspan='2'>&nbsp;</td><td width='71%'><font size='1' face='Verdana'><b>");
    echo mysql_result($result,$j,"NewsTitle");
    echo ("</b></font></td><td width='27%'><font size='1' face='Verdana'><b>");
    echo mysql_result($result,$j,"NewsDate");
    echo ("</b></font></td></tr><tr><td colspan='2'><font size='1' face='Verdana'>");
    echo mysql_result($result,$j,"NewsStory");
    echo ("</font></td></tr></table><br>");
    $i--;
}

That is how i found the way around it.
RE: I need PHP/MySQL help again by WDZ on 02-07-2005 at 04:35 AM

Have you tried simply adding ORDER BY in your query? For example...

code:
SELECT * FROM news_table ORDER BY NewsNum

RE: I need PHP/MySQL help again by Ahmad on 02-07-2005 at 06:05 AM

you can also add ASC (ascending) or DESC (descending) onto the end of that (Y)


RE: I need PHP/MySQL help again by Eljay on 02-07-2005 at 07:48 AM

code:
$query = mysql_query("SELECT * FROM news_table ORDER by NewsNum");
while($array = mysql_fetch_array($query)) {
echo "<table border='0' width='421' id='table1' cellspacing='0' cellpadding='0'><tr><td width='2%' rowspan='2' background='images/border.gif'>&nbsp;</td><td width='2%' rowspan='2'>&nbsp;</td><td width='71%'><font size='1' face='Verdana'><b>".$array[NewsTitle]."</b></font></td><td width='27%'><font size='1' face='Verdana'><b>".$array[NewsDate]."</b></font></td></tr><tr><td colspan='2'><font size='1' face='Verdana'>".$array[NewsStory]."</font></td></tr></table><br>";
}
?>