jaku78 Posted April 25, 2007 Share Posted April 25, 2007 I'm having some trouble with looping a sequence to get data from SQL to appear, I don't know if it's my technique to get it in PHP, but it always has the same information on each message if there is multiple messages, here is the code: <html> <head> <LINK href="style.css" rel="stylesheet" type="text/css"> <?php $title="Inbox"; require("navtemp.inc"); require("serverinfo.inc"); if (isset($_COOKIE['userid'])) { $username=$_COOKIE['username']; echo "Welcome ".$username." to your inbox!<br />"; echo "<a href='newPM.html' target='_blank'>Compose a new message</a><br />"; } else { die("Your not logged in! Log in!"); } $formset= <<<END <form action='deletemsg.php' method='post'> END; $tablehead = <<<END <table align='center'> <tr border='1'><td>FROM</td><td>SUBJECT</td><td>CREATED</td><td>DELETE</td><td>VIEW</td></tr> END; $tableend = "</table></div></body></html>"; echo $tablehead; $sql="SELECT * FROM myPM WHERE pmto='$username'"; $query=mysql_query($sql) or die(mysql_error()); $countbox=mysql_num_rows($query); if ($countbox > 0) { while ($countbox > 0) { $sql1="SELECT * FROM myPM WHERE pmto='$username'"; $query1=mysql_query($sql1) or die(mysql_error()); $msg1=mysql_fetch_assoc($query1) or die(mysql_error()); echo "<tr><td>".$msg1['pmfrom']."</td><td>".$msg1['pmtitle']."</td><td>".$msg1['pmdate']."</td><td>".$formset."<input type='hidden' name='msg' value='".$msg1['pmid']."'><input type='submit' value='delete'></form></td><td><form method='post' action='viewmsg.php'><input type='hidden' name='viewmsg' value='".$msg1['pmid']."'><input type='submit' value='view'></form></td></tr>"; $countbox = $countbox - 1; } } else { echo "<tr><td rowspan=5>You have no new messages.</td></tr>"; } echo $tableend; ?> The counter seems to work fine, but how it's listing the messages is the problem, any ideas? Thanks in advance! Quote Link to comment Share on other sites More sharing options...
jaku78 Posted April 25, 2007 Author Share Posted April 25, 2007 It's definately the while loop in the code, any ideas please? Quote Link to comment Share on other sites More sharing options...
jaku78 Posted April 26, 2007 Author Share Posted April 26, 2007 Bumping this so people can see it, I'm patient, but people will not notice it if it's on the bottom of page 3. Quote Link to comment Share on other sites More sharing options...
taith Posted April 26, 2007 Share Posted April 26, 2007 here ya go... simplified :-) <html> <head> <LINK href="style.css" rel="stylesheet" type="text/css"> <?php $title="Inbox"; require("navtemp.inc"); require("serverinfo.inc"); if(isset($_COOKIE['userid'])){ $username=$_COOKIE['username']; echo "Welcome ".$username." to your inbox!<br />"; echo "<a href='newPM.html' target='_blank'>Compose a new message</a><br />"; }else die("Your not logged in! Log in!"); $body.='<form action="deletemsg.php" method="post">'; $body.='<table align="center"><tr border="1"><td>FROM</td><td>SUBJECT</td><td>CREATED</td><td>DELETE</td><td>VIEW</td></tr>'; $query=mysql_query("SELECT * FROM myPM WHERE pmto='$username'") or die(mysql_error()); if(mysql_num_rows($query)>0){ while($row=mysql_fetch_assoc($query)){ $body.=' <tr>'; $body.=' <td>'.$msg1['pmfrom'].'</td>'; $body.=' <td>'.$msg1['pmtitle'].'</td>'; $body.=' <td>'.$msg1['pmdate'].'</td>'; $body.=' <td>'.$formset.'<input type="hidden" name="msg" value="'.$msg1['pmid'].'"><input type="submit" value="delete"></form></td>'; $body.=' <td><form method="post" action="viewmsg.php"><input type="hidden" name="viewmsg" value="'.$msg1['pmid'].'"><input type="submit" value="view"></form></td>'; $body.=' </tr>"; } }else $body.='<tr><td rowspan=5>You have no new messages.</td></tr>'; $body.='</table></div></body></html>'; echo $body; ?> sorry... did about a dozen updates... it should be done now :-) Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted April 26, 2007 Share Posted April 26, 2007 what exactlt is the problem you are experiencing? 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.