Help inbox group by user

Started on the old forum in July 2013 · view the original in the archive · old links redirect here

1 reply · 515 views · started 13 years ago · 3 min read

2 participants
wasted05 Junior · 11 posts #1
///////////////////////////// in box main

addonline(getuid_sid($sid),"inbox","");
addplace(getuid_sid($sid),"inbox","");
 echo "<title>site-Inbox</title>";
  $theme = mysql_fetch_array(mysql_query("SELECT theme FROM database_users WHERE id='".$uid."'"));
 echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"/style/$theme[0]\" />";
  echo "</head>";

include("top.php");
echo "<div class=\"announcement\">";
echo "<b>Private Messages</div></b>";

echo "<meta http-equiv=\"refresh\" content=\"20; URL= inbox.php?page=$page&time=";
 echo date('dmHis');
 echo "\">";

 echo "<div class='box'><div class=\"div\"><a href=\"inbox.php\">Inbox</a> <b>·</b>  ";
 echo "<a href=\"inbox.php?ac=myfolder\">My Folder</a></div> </div>  ";
  
 mysql_query("UPDATE cc0801_private SET newpm='0' WHERE touid='".$uid."' AND newpm='1'");

  $opt = $_POST["opt"];

$uid = getuid_sid($sid);
if($opt=="3")
    {

$checkbox = $_POST["checkbox"];
if (empty($checkbox))
 {
 echo "Pls select one or more messages to delete<br/>";
}else{
$count = count($checkbox);
for($i=0; $i < $count; $i++)
{ 
$res = mysql_query("DELETE FROM cc0801_private WHERE id='".safe(cleanInput($checkbox[$i]))."' AND touid='".$uid."'");
 
}
if($res)
    {
if($count=="1")
    {
echo "$count message deleted successfully<br/>";
 }else{
 echo "$count messages deleted successfully<br/>";
     }
 }else{
 echo "Pls try again later<br/>";
  }
}
}else
if($opt=="4")
    {

$cou = mysql_fetch_array(mysql_query("SELECT COUNT(id) FROM cc0801_private WHERE touid='".$uid."' AND starred='1'"));
    if($cou[0]>50)
    {
      echo "You have already 50 messages in your folder<br/>";
}else{
$checkbox = $_POST["checkbox"];
if (empty($checkbox))
 {
 echo "Pls select one or more messages to move<br/>";
}else{
$count = count($checkbox);
for($i=0; $i < $count; $i++)
{ 
$res = mysql_query("UPDATE cc0801_private SET starred='1' WHERE id='".safe(cleanInput($checkbox[$i]))."' AND touid='".$uid."'");
}
if($res)
    {
  if($count=="1")
    {
 echo "$count message move to folder successfully<br/>";
  }else{
 echo "$count messages move to folder successfully<br/>";
    }
 }else{
 echo "Pls try again later<br/>";
  }
}
}

}
echo "<div class='box'>";
    //////ALL LISTS SCRIPT <<
   // if($view=="")$view="all";
    if($page=="" || $page<=0)$page=1;
    
    $msgi = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM cc0801_private WHERE touid='".$uid."'"));
       $today = date("dF20y");
$doit=false;
    $num_items = $msgi[0]; //changable
    $items_per_page= 10;
    $num_pages = ceil($num_items/$items_per_page);
    if($page>$num_pages)$page= $num_pages;
    $limit_start = ($page-1)*$items_per_page;
    if($num_items>0)
    {
    //changable sql
   
    $sql = "SELECT
            a.name, a.bmizt_rank, b.id, b.byuid, b.unread, b.text, b.timesent FROM database_users a
              INNER JOIN cc0801_private b ON a.id = b.byuid
            WHERE b.touid='".$uid."'  GROUP BY  b.byuid
            ORDER BY  b.timesent DESC LIMIT $limit_start, $items_per_page
    ";

    $items = mysql_query($sql);
    echo mysql_error();

 while ($item = mysql_fetch_array($items))
    {

 $bm = mysql_fetch_array(mysql_query("SELECT id FROM database_users WHERE id='".$item[0]."'"));
$who = getuid_nick($item[0]);

      $avlink = getavatar($who);

echo "<div class='padding'>";
      if($item[4]=="1")
      {
    $lnk = "<img src=\"img/npm.png\" width=\"20\" height=\"20\"/><img class=\"bm\"  src=\"$avlink\" alt=\"$id\" width=\"20\" height=\"20\"/><a href=\"inbox.php?ac=readmsg&who=$item[3]&pmid=$item[2]\"><font color=\"".ncolor($who)."\">$item[0]</font><a href=\"inbox.php?ac=readmsg&who=$item[3]&pmid=$item[2]\"></a>";
      }  
     else if($item[4]=="2")
      {
    $lnk = "<img src=\"img/ofpm.png\" width=\"20\" height=\"20\"/><img class=\"bm\"  src=\"$avlink\" alt=\"$id\" width=\"20\" height=\"20\"/><a href=\"inbox.php?ac=read&who=$item[3]&pmid=$item[2]\"><font color=\"".ncolor($who)."\">$item[0]</font></a>";
  
      }else {
    
    $lnk = "<img src=\"img/opm.png\" width=\"20\" height=\"20\"/><img class=\"bm\"  src=\"$avlink\" alt=\"$id\" width=\"20\" height=\"20\"/><a href=\"inbox.php?ac=read&who=$item[3]&pmid=$item[2]\"><font color=\"".ncolor($who)."\">$item[0]</font></a>";
      }  

$number = strlen($item[5]);
if($number>10)
{
 $text = substr("$item[5]", 0, 10);  
 $text = parsetitle($text);
 $text = "$text...";
}else{
 $text = substr("$item[5]", 0, 10);  
 $text = parsetitle($text);
}
      
 echo "$lnk $text";

     
/*
 $tmstamp = $item[6];
   
 $ndate = date("dF20y", $tmstamp); 
 $today = date("dF20y");
 $mday = date("d")-1;
 if($mday>9)
 {
 $yesterday = date("".$mday."F20y");
 }else{
 $yesterday = date("0".$mday."F20y");
 }

 if($ndate==$today)
 {
 $timetxt = date("h:i:sa", $tmstamp); 
 echo "<small>Today - $timetxt</small>";
 }else
 if($ndate==$yesterday)
 {
 $timetxt = date("h:i:sa", $tmstamp); 
  echo "<small>Yesterday - $timetxt</small>";
 }else{
 $timetxt = date("dF20y - h:i:sa", $tmstamp); 
    echo "<small>$timetxt</small>";
 }*/
echo "</div>";
    }
	
////echo " <select name=\"opt\">";
 if($opt=="1")
      {
////echo "<option value=\"2\">Unmark All</option>";

 }else{
///echo "<option value=\"1\">Mark All</option>";
}
///echo "<option value=\"3\" selected>Delete</option>";
///echo "<option value=\"4\">Move to My Folder</option>";
///echo "</select>";
///echo "<input type=\"submit\" class=\"button\" value=\"Submit\"/>";
///echo "</form>";
$unreadinbox=mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM cc0801_private WHERE unread='1' AND touid='".$uid."'"));
$unrd="".$unreadinbox[0]."";
echo"</div>";
echo "<div class='box'>You Have <b>$unrd</b> Unred PM</div>";
echo "<div class=\"e\">";

   ////page
   if($num_pages>1)
    {
 echo "<div class='nav'>";

 if($page>2)
  {
 echo "<a href=\"inbox.php?page=1\">1</a>  ";

  $ppage = $page-1;
  echo "<a href=\"inbox.php?page=$ppage\"><<</a> ";
  }

///
 if($page>3)
  {
  $pageA = $page-2;
  echo "<a href=\"inbox.php?page=$pageA\">$pageA</a> ";
 }
 if($page>1)
  {
  $pageB = $page-1;
  echo "<a href=\"inbox.php?page=$pageB\">$pageB</a> ";

 
  }

  if($page<$num_pages||$page>1)
    {
 echo " <span class='navcurrent'>$page</span> ";
    }

      if($page<$num_pages)
    {
  $pageC = $page+1;
  echo "<a href=\"inbox.php?page=$pageC\">$pageC</a> ";
   }

  if($page<$num_pages-2)
    {
  $pageD = $page+2;
  echo "<a href=\"inbox.php?page=$pageD\">$pageD</a> ";
  
  }
//
      if($page+1<$num_pages)
    {
      $npage = $page+1;
    echo "<a href=\"inbox.php?page=$npage\">>></a>";

    echo "   <a href=\"inbox.php?page=$num_pages\">$num_pages</a>";
    }

    echo "</div>"; 

    if($num_pages>2)
    {
    $rets = "<form action=\"inbox.php\" method=\"get\">";
    $rets .= "Jump to page: <input name=\"page\" style=\"-wap-input-format: '*N'\" size=\"3\"/>";
    $rets .= "<input type=\"submit\" class=\"button\" value=\"Go\"/>";

   // $rets .= "<input type=\"hidden\" name=\"rid\" value=\"$rid\"/>";
    $rets .= "</form>";
    echo $rets;
  
    }
   }
   
echo"</div></table></div>";

    }else{
   
      echo "No new messages<hr/>";
     
    }
  ////// UNTILL HERE >>

echo "<div class=\"div\"><a href=\"inbox.php?ac=deleteread&confirm=1\">Delete Read</a><br/>";
echo "<a href=\"inbox.php?ac=emptyinbox&confirm=1\">Empty Inbox</a><br/>";
/////echo "<a href=\"inbox.php?ac=sendto\">Send Message</a>";

 echo "</div>";
 
}
  if($rid!="")
  {
echo "<a href=\"chat.php?rid=$rid\">Back To Chat</a><br/>";
  }
 include("foot.php");

Its already group by user. but when comes a new pm, the new pm cant see.. can you help me guys?

something else Fellow · 2,296 posts #2

You have 2 column names "newpm" and "unread" is this a mistake or is this used for something different? also you have a lot of calls to database and having that page on refresh will slow your site down (lava is like that pretty much all over) I was bored last night so just had a quick tidy up with it:

<?php
///////////////////////////// inbox main 
$uid = getuid_sid($sid);

addonline($uid,"inbox",""); 
addplace($uid,"inbox","");  //can these 2 functioned be moved into 1?

$theme = mysql_fetch_array(mysql_query("SELECT theme FROM database_users WHERE id='".$uid."'"));
$rets = "<title>site-Inbox</title>"; 
$rets .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"/style/$theme[0]\" />"; 
echo $rets."</head>"; 

include("top.php"); 

$rets = "<div class=\"announcement\">"; 
$rets .= "<b>Private Messages</div></b>"; 
$rets .= "<meta http-equiv=\"refresh\" content=\"20; URL= inbox.php?page=$page&time=".date('dmHis')."\">"; 
$rets .= "<div class=\"box\"><div class=\"div\"><a href=\"inbox.php\">Inbox</a> <b>·</b>  "; 
echo $rets."<a href=\"inbox.php?ac=myfolder\">My Folder</a></div> </div>  "; 
   
mysql_query("UPDATE cc0801_private SET newpm='0' WHERE touid='".$uid."' AND newpm='1'");  // call here to table coloumn called "newpm" is this not the same as "unread" (a coloumn name on line 156)

$opt = $_POST["opt"]; 

if($opt == 3) 
{ 
	$checkbox = $_POST["checkbox"]; 
	if (empty($checkbox)) 
	{ 
		echo "Please select one or more messages to delete<br/>"; 
	}
	else
	{ 
		$count = count($checkbox); 		
		$sqli = "";
		for($i = 0; $i < $count; $i++) 
		{
			$or = ($i != $count - 1 ? " OR " : ""); 
			$sqli .= "id='".safe(cleanInput($checkbox[$i]))."' AND touid='".$uid."'".$or;
		}
		$res = mysql_query("DELETE FROM cc0801_private WHERE $sqli");
			
		if($res)
		{ 
			$s = ($count > 1 ? "s" : ""); 
			echo $count."message".$s." deleted successfully<br/>"; 
		}
		else
		{ 
			echo "Please try again later<br/>"; 
		} 
	} 
}
else if($opt == 4) 
{ 
	$cou = mysql_fetch_array(mysql_query("SELECT COUNT(id) FROM cc0801_private WHERE touid='".$uid."' AND starred='1'")); 
	if($cou[0] > 50) 
	{ 
		echo "You have already 50 messages in your folder<br/>"; 
	}
	else
	{ 
		$checkbox = $_POST["checkbox"]; 
		if (empty($checkbox)) 
		{ 
			echo "Please select one or more messages to move<br/>"; 
		}
		else
		{ 
			$count = count($checkbox); 
			$sqli = "";
			
			for($i = 0; $i < $count; $i++) 
			{
				$or = ($i != $count - 1 ? " OR " : ""); 
				$sqli .= "id='".safe(cleanInput($checkbox[$i]))."' AND touid='".$uid."'".$or;
			}
			
			$res = mysql_query("UPDATE cc0801_private SET starred='1' WHERE $sqli");
			
			if($res)
			{ 
				$s = ($count > 1 ? "s" : ""); 
				echo $count."message".$s." moved to folder successfully<br/>"; 
			}
			else
			{ 
				echo "Pls try again later<br/>"; 
			} 
		} 
	} 

}

echo "<div class=\"box\">"; 

if($page == "" || $page <= 0) $page = 1; 
     
	$msgi = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM cc0801_private WHERE touid='".$uid."'")); 
	$today = date("dF20y"); 
	$doit = false; 
    $num_items = $msgi[0]; 
    $items_per_page = 10; 
    $num_pages = ceil($num_items / $items_per_page); 
    if($page > $num_pages) $page = $num_pages; 
    $limit_start = ($page - 1) * $items_per_page; 
    if($num_items > 0) 
    { 
		//changed the sql below to get uid and avatar to save calls to db    
		$sql = "SELECT 
            a.name, a.bmizt_rank, b.id, b.byuid, b.unread, b.text, b.timesent, a.uid, a,avatar 
			FROM database_users a INNER JOIN cc0801_private b ON a.id = b.byuid 
            WHERE b.touid='".$uid."'  GROUP BY  b.byuid 
            ORDER BY  b.timesent DESC LIMIT $limit_start, $items_per_page 
		"; 

		$items = mysql_query($sql); 
		//echo mysql_error(); //commented out due to easy way to crash sql and get database names etc

		while ($item = mysql_fetch_array($items)) 
		{ 
			//$bm = mysql_fetch_array(mysql_query("SELECT id FROM database_users WHERE id='".$item[0]."'")); // no idea what this is for 
			//$who = getuid_nick($item[0]);  //$who is now $item[7]
			//$avlink = getavatar($who); //$avlink is now £item[8] (see below)
			$avlink = $item[8];
			if($item[4] == 1)
			{ 
				$lnk = "<img src=\"img/npm.png\" width=\"20\" height=\"20\"/><img class=\"bm\"  src=\"$avlink\" alt=\"$id\" width=\"20\" height=\"20\"/><a href=\"inbox.php?ac=readmsg&who=$item[3]&pmid=$item[2]\"><font color=\"".ncolor($item[7])."\">$item[0]</font><a href=\"inbox.php?ac=readmsg&who=$item[3]&pmid=$item[2]\"></a>"; 
			}   
			else if($item[4] == 2 ) 
			{ 
				$lnk = "<img src=\"img/ofpm.png\" width=\"20\" height=\"20\"/><img class=\"bm\"  src=\"$avlink\" alt=\"$id\" width=\"20\" height=\"20\"/><a href=\"inbox.php?ac=read&who=$item[3]&pmid=$item[2]\"><font color=\"".ncolor($item[7])."\">$item[0]</font></a>"; 
   
			}
			else
			{ 
				$lnk = "<img src=\"img/opm.png\" width=\"20\" height=\"20\"/><img class=\"bm\"  src=\"$avlink\" alt=\"$id\" width=\"20\" height=\"20\"/><a href=\"inbox.php?ac=read&who=$item[3]&pmid=$item[2]\"><font color=\"".ncolor($item[7])."\">$item[0]</font></a>"; 
			}   

			$number = strlen($item[5]); 
			if($number > 10) 
			{ 
				$text = substr("$item[5]", 0, 10);   
				$text = parsetitle($text); 
				$text = "$text..."; 
			}
			else
			{ 
				$text = substr("$item[5]", 0, 10);   
				$text = parsetitle($text); 
			} 
       
			echo "<div class=\"padding\">$lnk $text </div>"; 
		} 

		$unreadinbox = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM cc0801_private WHERE unread='1' AND touid='".$uid."'"));

		echo "</div><div class=\"box\">You Have <b>".$unreadinbox[0]."</b> Unred PM</div><div class=\"e\">"; 

		if($num_pages > 1) 
		{ 
			echo "<div class=\"nav\">"; 

			if($page > 2) 
			{ 
				$ppage = $page - 1;
				echo "<a href=\"inbox.php?page=1\">1</a>  <a href=\"inbox.php?page=$ppage\"><<</a> "; 
			}
			
			if($page > 3) 
			{ 
				$pageA = $page - 2; 
				echo "<a href=\"inbox.php?page=$pageA\">$pageA</a> "; 
			} 
			
			if($page > 1) 
			{ 
				$pageB = $page - 1; 
				echo "<a href=\"inbox.php?page=$pageB\">$pageB</a> "; 
			} 

			if($page < $num_pages || $page > 1) 
			{ 
				echo " <span class='navcurrent'>$page</span> "; 
			} 

			if($page < $num_pages) 
			{ 
				$pageC = $page + 1; 
				echo "<a href=\"inbox.php?page=$pageC\">$pageC</a> "; 
			} 

			if($page < $num_pages - 2) 
			{ 
				$pageD = $page + 2; 
				echo "<a href=\"inbox.php?page=$pageD\">$pageD</a> "; 
			} 

			if($page + 1 < $num_pages) 
			{ 
				$npage = $page + 1; 
				echo "<a href=\"inbox.php?page=$npage\">>></a> <a href=\"inbox.php?page=$num_pages\">$num_pages</a>"; 
			} 

			echo "</div>";  

			if($num_pages > 2) 
			{ 
				$rets = "<form action=\"inbox.php\" method=\"get\">"; 
				$rets .= "Jump to page: <input name=\"page\" style=\"-wap-input-format: '*N'\" size=\"3\"/>"; 
				$rets .= "<input type=\"submit\" class=\"button\" value=\"Go\"/>"; 
				echo $rets."</form>";   
			} 
		} 
    
		echo"</div></table></div>"; 

    }
	else
	{ 
		echo "No new messages<hr/>";
    }

	$rets = "<div class=\"div\"><a href=\"inbox.php?ac=deleteread&confirm=1\">Delete Read</a><br/>"; 
	$rets .= "<a href=\"inbox.php?ac=emptyinbox&confirm=1\">Empty Inbox</a><br/>"; 
	echo $rets."</div>"; 
  
 
if($rid != "") 
{ 
	echo "<a href=\"chat.php?rid=$rid\">Back To Chat</a><br/>"; 
} 

include("foot.php"); 
?>

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close