<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
    <channel>
        <title>unreaded private messages on external page [solved]</title>
        <description> Hi,
our phorum is up and running perfectly.
because this phorum is also a replacement for our pm-system,
i would like to show on other pages of our website, 
the amount of unreaded private messages of the user.

i can&amp;#039;t find the used query for this, as it is used in phorums&amp;#039; private messages page?</description>
        <link>https://www.phorum.org/support/read.php?28,146558,146558#msg-146558</link>
        <lastBuildDate>Wed, 22 Jul 2026 02:22:32 -0500</lastBuildDate>
        <generator>Phorum 6.0.4</generator>
        <item>
            <guid>https://www.phorum.org/support/read.php?28,146558,146573#msg-146573</guid>
            <title>Re: unreaded private messages on external page</title>
            <link>https://www.phorum.org/support/read.php?28,146558,146573#msg-146573</link>
            <description><![CDATA[ For archiving purpose, this is what works for us:<br />
<br />
remember, as stated before, i personally think that the amount of unreaded private messages is of no use for an user, it is about notifying your users that they just have unreaded messages! More info is a waste of resources, which is important, because you will probably use this on every page of your website (a mark in your menu?).<br />
<br />
[code=&quot;php&quot;]<br />
function get_phorum_id($your_username)<br />
{<br />
	// get phorum-userid based on your websites  user session-variable<br />
	// for use anywhere in your site<br />
	// assuming $your_username is a safe variable<br />
	// database connection must exist for using this function<br />
	// example use: $i_phorum_userid = get_phorum_id($_SESSION[&#039;nick&#039;]);<br />
 <br />
	$q = &quot;SELECT user_id FROM phorum__users WHERE username = &#039;&quot;.$your_username.&quot;&#039; LIMIT 1&quot;;<br />
	$exec = mysql_query($q);<br />
	<br />
	// error check<br />
	if(!$exec)<br />
	{<br />
		// failed query =&gt; use your own error handling<br />
		return false;<br />
	}<br />
	else<br />
	{<br />
		$a_result = mysql_fetch_assoc($exec);<br />
		$i_phorum_userid = $a_result[&#039;user_id&#039;];<br />
		<br />
		return $i_phorum_userid;<br />
	}<br />
}<br />
<br />
<br />
function unread_pm($i_phorum_userid)<br />
{<br />
	/*<br />
	get status of unreaded private messages anywhere in your website<br />
	for use anywhere in your site<br />
	assuming $i_phorum_userid is a safe variable<br />
	database connection must exist for using this function<br />
	example use: <br />
	$b_unread_pm = unread_pm($i_phorum_userid); // return true or false<br />
	if($b_unread_pm)<br />
	{<br />
		//show somehow they have unreaded pm&#039;s :)<br />
	}<br />
	*/<br />
 <br />
	$q = &quot;SELECT COUNT(*) AS i FROM phorum__pm_xref WHERE user_id = &#039;&quot;.$i_phorum_userid.&quot;&#039; AND read_flag = &#039;0&#039; LIMIT 1&quot;;<br />
	$exec = mysql_query($q);<br />
	<br />
	// error check<br />
	if(!$exec)<br />
	{<br />
		// failed query =&gt; use your own error handling<br />
		return false;<br />
	}<br />
	else<br />
	{<br />
		$a_result = mysql_fetch_assoc($exec);<br />
		<br />
		if($a_result[&#039;i&#039;] == 1)<br />
			return true;<br />
		else<br />
			return false;<br />
	}<br />
}<br />
[/code]<br />
<br />
Everybody: enjoy this perfect Phorum!]]></description>
            <dc:creator>Terradon</dc:creator>
            <category>Phorum Integration</category>
            <pubDate>Fri, 29 Oct 2010 06:59:23 -0500</pubDate>
        </item>
        <item>
            <guid>https://www.phorum.org/support/read.php?28,146558,146565#msg-146565</guid>
            <title>Re: unreaded private messages on external page</title>
            <link>https://www.phorum.org/support/read.php?28,146558,146565#msg-146565</link>
            <description><![CDATA[ If you only want to know whether there are new messages or not, then add the limit = 1 too. That will save the database the work of providing a full record count.]]></description>
            <dc:creator>Maurice Makaay</dc:creator>
            <category>Phorum Integration</category>
            <pubDate>Thu, 28 Oct 2010 18:35:22 -0500</pubDate>
        </item>
        <item>
            <guid>https://www.phorum.org/support/read.php?28,146558,146564#msg-146564</guid>
            <title>Re: unreaded private messages on external page</title>
            <link>https://www.phorum.org/support/read.php?28,146558,146564#msg-146564</link>
            <description><![CDATA[ Yessssssssss, that is what i was looking for,<br />
just didn&#039;t notice the xref table!<br />
<br />
now it is a simple count() query on (phorum)userid where flag = o<br />
<br />
thanks!]]></description>
            <dc:creator>Terradon</dc:creator>
            <category>Phorum Integration</category>
            <pubDate>Thu, 28 Oct 2010 18:20:03 -0500</pubDate>
        </item>
        <item>
            <guid>https://www.phorum.org/support/read.php?28,146558,146563#msg-146563</guid>
            <title>Re: unreaded private messages on external page</title>
            <link>https://www.phorum.org/support/read.php?28,146558,146563#msg-146563</link>
            <description><![CDATA[ The query does not check the pm messages table, but the related xref table. The xref table is where the read flag is implemented. The flag is not in the message itself, because the message is shared between all that receive the message (and optionally the sender when keeping a copy in the outbox.)<br />
<br />
If you want to use the function phorum_db_pm_checknew(), you will have to include common.php, which will load the database settings and the db layer library. It is not needed as such, since you can also program the query in a stand-along piece of code using your favorite MySQL access method from your own code.]]></description>
            <dc:creator>Maurice Makaay</dc:creator>
            <category>Phorum Integration</category>
            <pubDate>Thu, 28 Oct 2010 18:13:48 -0500</pubDate>
        </item>
        <item>
            <guid>https://www.phorum.org/support/read.php?28,146558,146562#msg-146562</guid>
            <title>Re: unreaded private messages on external page</title>
            <link>https://www.phorum.org/support/read.php?28,146558,146562#msg-146562</link>
            <description><![CDATA[ mm...<br />
found this in phorum__pm_messages, rule 6000+ :)<br />
<br />
[code=&quot;php&quot;]<br />
// {{{ Function: phorum_db_pm_checknew()<br />
/**<br />
 * Check if the user has any new private messages. This is useful in case<br />
 * you only want to know whether the user has new messages or not and when<br />
 * you are not interested in the exact amount of new messages.<br />
 *<br />
 * @param mixed $user_id<br />
 *     The user to check for or NULL to use the active Phorum user (default).<br />
 *<br />
 * @return boolean<br />
 *     TRUE in case there are new messages, FALSE otherwise.<br />
 */<br />
function phorum_db_pm_checknew($user_id = NULL)<br />
{<br />
    $PHORUM = $GLOBALS[&#039;PHORUM&#039;];<br />
<br />
    if ($user_id === NULL) $user_id = $PHORUM[&#039;user&#039;][&#039;user_id&#039;];<br />
    settype($user_id, &#039;int&#039;);<br />
<br />
    $new = phorum_db_interact(<br />
        DB_RETURN_VALUE,<br />
        &quot;SELECT user_id<br />
         FROM   {$PHORUM[&#039;pm_xref_table&#039;]}<br />
         WHERE  user_id   = $user_id AND<br />
                read_flag = 0 LIMIT 1&quot;<br />
    );<br />
<br />
    return (bool)$new;<br />
}<br />
// }}}<br />
[/code]<br />
<br />
there is no field read_flag in table phorum__pm_messages,<br />
it is packed inside a bunch of other values in the field meta<br />
i really do not understand how to retrieve this value??<br />
<br />
For now i just am thinking of:<br />
when visitor logs in on the site, i have to retrieve his phorum userid.<br />
and to use the mentioned function, i have to include something of phorum to get it working?<br />
<br />
maybe i haven&#039;t explained it clearly, but i wanted to check for new mesages, while the visitor is on my site, but not in the phorum pages.]]></description>
            <dc:creator>Terradon</dc:creator>
            <category>Phorum Integration</category>
            <pubDate>Thu, 28 Oct 2010 17:44:37 -0500</pubDate>
        </item>
        <item>
            <guid>https://www.phorum.org/support/read.php?28,146558,146561#msg-146561</guid>
            <title>Re: unreaded private messages on external page</title>
            <link>https://www.phorum.org/support/read.php?28,146558,146561#msg-146561</link>
            <description><![CDATA[ thanks, <br />
in my opinion a user only needs an indication <u>IF</u> he/she has new messages,<br />
how <u>many isn&#039;t relevant</u>. a waste of resources. <br />
<br />
but from what i have seen, i just cannot use a simple standalone query in my websites&#039; mainmenu?<br />
in the database i see a bunch of codes in the field meta, from which i cant get a marker for newmessages?<br />
<br />
i will try to go on anyway:)]]></description>
            <dc:creator>Terradon</dc:creator>
            <category>Phorum Integration</category>
            <pubDate>Thu, 28 Oct 2010 17:38:30 -0500</pubDate>
        </item>
        <item>
            <guid>https://www.phorum.org/support/read.php?28,146558,146559#msg-146559</guid>
            <title>Re: unreaded private messages on external page</title>
            <link>https://www.phorum.org/support/read.php?28,146558,146559#msg-146559</link>
            <description><![CDATA[ The function from the db layer is:<br />
<pre class="bbcode">
function phorum_db_pm_checknew($user_id = NULL)</pre>
<br />
For performance reasons, this one does not contain the message count. It only checks if there are new messages available. For friendly retrieval of the new message count, I would like to implement a counter in the user data that holds the active new message count, so no query is needed for doing the counting and checking anymore. That will be a Phorum 5.3 feature though, so for now you&#039;ll have to go with this query function.<br />
<br />
If you want the total message count, then you&#039;ll have to take this function as the basis for writing your own function. It shouldn&#039;t be really hard to modify the function to retrieve a total new message count.]]></description>
            <dc:creator>Maurice Makaay</dc:creator>
            <category>Phorum Integration</category>
            <pubDate>Thu, 28 Oct 2010 17:21:38 -0500</pubDate>
        </item>
        <item>
            <guid>https://www.phorum.org/support/read.php?28,146558,146558#msg-146558</guid>
            <title>unreaded private messages on external page [solved]</title>
            <link>https://www.phorum.org/support/read.php?28,146558,146558#msg-146558</link>
            <description><![CDATA[ Hi,<br />
our phorum is up and running perfectly.<br />
because this phorum is also a replacement for our pm-system,<br />
i would like to show on other pages of our website, <br />
the amount of unreaded private messages of the user.<br />
<br />
i can&#039;t find the used query for this, as it is used in phorums&#039; private messages page?]]></description>
            <dc:creator>Terradon</dc:creator>
            <category>Phorum Integration</category>
            <pubDate>Thu, 28 Oct 2010 16:53:26 -0500</pubDate>
        </item>
    </channel>
</rss>
