Jump to content

Mail Inbox Looping


jaku78

Recommended Posts

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!

Link to comment
Share on other sites

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 :-)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.