What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » I need PHP/MySQL help again

I need PHP/MySQL help again
Author: Message:
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
O.P. Huh?  I need PHP/MySQL help again
[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.

.gif File Attachment: phpMyAdmin.gif (9.87 KB)
This file has been downloaded 168 time(s).

This post was edited on 02-07-2005 at 12:54 AM by matty.
02-07-2005 12:18 AM
Profile E-Mail PM Find Quote Report
WDZ
Former Admin
*****

Avatar

Posts: 7106
Reputation: 107
– / Male / Flag
Joined: Mar 2002
RE: I need PHP/MySQL help again
Have you tried simply adding ORDER BY in your query? For example...

code:
SELECT * FROM news_table ORDER BY NewsNum
02-07-2005 04:35 AM
Profile PM Web Find Quote Report
Ahmad
Senior Member
****

Avatar
@hmad

Posts: 526
Reputation: 27
40 / Male / –
Joined: Dec 2004
RE: I need PHP/MySQL help again
you can also add ASC (ascending) or DESC (descending) onto the end of that (Y)
02-07-2005 06:05 AM
Profile PM Web Find Quote Report
Eljay
Elite Member
*****

Avatar
:O

Posts: 2949
Reputation: 77
– / Male / –
Joined: May 2004
RE: I need PHP/MySQL help again
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>";
}
?>

02-07-2005 07:48 AM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On