<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[PunBB Forums — How do MySQL queries in PunBB work?]]></title>
		<link>https://punbb.informer.com/forums/topic/21167/how-do-mysql-queries-in-punbb-work/</link>
		<atom:link href="https://punbb.informer.com/forums/feed/rss/topic/21167/" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in How do MySQL queries in PunBB work?.]]></description>
		<lastBuildDate>Wed, 15 Apr 2009 08:12:48 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: How do MySQL queries in PunBB work?]]></title>
			<link>https://punbb.informer.com/forums/post/126787/#p126787</link>
			<description><![CDATA[<p>I think it&#039;s better to use the function utf8_substr, not substr. utf8_substr is defined in the forum core.</p>]]></description>
			<author><![CDATA[null@example.com (Parpalak)]]></author>
			<pubDate>Wed, 15 Apr 2009 08:12:48 +0000</pubDate>
			<guid>https://punbb.informer.com/forums/post/126787/#p126787</guid>
		</item>
		<item>
			<title><![CDATA[Re: How do MySQL queries in PunBB work?]]></title>
			<link>https://punbb.informer.com/forums/post/126772/#p126772</link>
			<description><![CDATA[<p>To limit the length of a message use this code:<br /></p><div class="codebox"><pre><code>define(&#039;MAX_MESSAGE_LENGTH&#039;, 100);
...
&lt;p&gt;&#039;.substr($message, 0, MAX_MESSAGE_LENGTH).&#039;&lt;/p&gt;&#039;;</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Slavok)]]></author>
			<pubDate>Tue, 14 Apr 2009 14:24:38 +0000</pubDate>
			<guid>https://punbb.informer.com/forums/post/126772/#p126772</guid>
		</item>
		<item>
			<title><![CDATA[Re: How do MySQL queries in PunBB work?]]></title>
			<link>https://punbb.informer.com/forums/post/126739/#p126739</link>
			<description><![CDATA[<p>Oke, that code works great! Thanks!!</p><p>One question though: How can I limit the number of characters that are displayed, because at the moment the complete first post is showing on the frontpage.</p>]]></description>
			<author><![CDATA[null@example.com (VincentBroccoli)]]></author>
			<pubDate>Sun, 12 Apr 2009 18:41:24 +0000</pubDate>
			<guid>https://punbb.informer.com/forums/post/126739/#p126739</guid>
		</item>
		<item>
			<title><![CDATA[Re: How do MySQL queries in PunBB work?]]></title>
			<link>https://punbb.informer.com/forums/post/126094/#p126094</link>
			<description><![CDATA[<div class="quotebox"><cite>VincentBroccoli wrote:</cite><blockquote><p>- And the line</p><div class="codebox"><pre><code>&lt;a href=&quot;&#039;. FORUM_ROOT .&#039;viewtopic.php?id=&#039;.$cur_post[&#039;id&#039;].&#039;&quot; title=&quot;View Replies&quot; &gt;&#039;.$cur_post[&#039;num_replies&#039;].&#039; Comments&lt;/a&gt;</code></pre></div><p>links to the post id not to the topic id. How can I fix that?</p></blockquote></div><p>Modify &#039;SELECT&#039; key in array:<br /></p><div class="codebox"><pre><code>    &#039;SELECT&#039;    =&gt;    &#039;p.id, p.message, t.subject, t.poster, t.num_replies, t.posted, p.poster_id, t.num_replies, t.id AS tid&#039;,</code></pre></div><p>And link will look like this:<br /></p><div class="codebox"><pre><code>&lt;a href=&quot;&#039;. FORUM_ROOT .&#039;viewtopic.php?id=&#039;.$cur_post[&#039;tid&#039;].&#039;&quot; title=&quot;View Replies&quot; &gt;&#039;.$cur_post[&#039;num_replies&#039;].&#039; Comments&lt;/a&gt;</code></pre></div><p>Code </p><div class="codebox"><pre><code>&#039;ORDER BY&#039;    =&gt; &#039;t.posted DESC&#039;,
&#039;LIMIT&#039;            =&gt; &#039;0,10&#039; </code></pre></div><p>work fine for me to limit the numbers of topics.</p>]]></description>
			<author><![CDATA[null@example.com (Slavok)]]></author>
			<pubDate>Wed, 25 Mar 2009 09:12:17 +0000</pubDate>
			<guid>https://punbb.informer.com/forums/post/126094/#p126094</guid>
		</item>
		<item>
			<title><![CDATA[Re: How do MySQL queries in PunBB work?]]></title>
			<link>https://punbb.informer.com/forums/post/126081/#p126081</link>
			<description><![CDATA[<div class="quotebox"><cite>pepak wrote:</cite><blockquote><p>Well, I guess - but really, if someone is unfamiliar with both PHP and SQL, how can he ever hope to make meaningful changes to the code?</p></blockquote></div><p>No-one is born a programmer.</p>]]></description>
			<author><![CDATA[null@example.com (MattF)]]></author>
			<pubDate>Tue, 24 Mar 2009 22:17:16 +0000</pubDate>
			<guid>https://punbb.informer.com/forums/post/126081/#p126081</guid>
		</item>
		<item>
			<title><![CDATA[Re: How do MySQL queries in PunBB work?]]></title>
			<link>https://punbb.informer.com/forums/post/126071/#p126071</link>
			<description><![CDATA[<div class="quotebox"><cite>VincentBroccoli wrote:</cite><blockquote><div class="codebox"><pre><code>&lt;a href=&quot;&#039;. FORUM_ROOT .&#039;viewtopic.php?id=&#039;.$cur_post[&#039;id&#039;].&#039;&quot; title=&quot;View Replies&quot; &gt;&#039;.$cur_post[&#039;num_replies&#039;].&#039; Comments&lt;/a&gt;</code></pre></div><p>links to the post id not to the topic id. How can I fix that?</p></blockquote></div><p>Are you sure? It sure looks like a topic link.<br />Maybe (MAYBE!) it should be $cur_post[&#039;topic_id&#039;]?</p>]]></description>
			<author><![CDATA[null@example.com (pepak)]]></author>
			<pubDate>Tue, 24 Mar 2009 19:56:52 +0000</pubDate>
			<guid>https://punbb.informer.com/forums/post/126071/#p126071</guid>
		</item>
		<item>
			<title><![CDATA[Re: How do MySQL queries in PunBB work?]]></title>
			<link>https://punbb.informer.com/forums/post/126070/#p126070</link>
			<description><![CDATA[<div class="quotebox"><cite>MattF wrote:</cite><blockquote><div class="quotebox"><cite>pepak wrote:</cite><blockquote><p>What&#039;s the problem? Building a real query is hardly any more than concatecating all keys and values into one string.</p></blockquote></div><p>Just because you may be familiar with php and SQL does not mean that everyone is.</p></blockquote></div><p>Well, I guess - but really, if someone is unfamiliar with both PHP and SQL, how can he ever hope to make meaningful changes to the code?</p>]]></description>
			<author><![CDATA[null@example.com (pepak)]]></author>
			<pubDate>Tue, 24 Mar 2009 19:53:30 +0000</pubDate>
			<guid>https://punbb.informer.com/forums/post/126070/#p126070</guid>
		</item>
		<item>
			<title><![CDATA[Re: How do MySQL queries in PunBB work?]]></title>
			<link>https://punbb.informer.com/forums/post/126053/#p126053</link>
			<description><![CDATA[<p>Thank you very much Slavok!</p><p>But I have two questions:</p><p>- How do I limit the numbers of topics displayed?</p><div class="codebox"><pre><code>&#039;LIMIT&#039;    =&gt; &#039;0,10&#039;</code></pre></div><p>The LIMITline doesn&#039;t work.</p><p>- And the line</p><div class="codebox"><pre><code>&lt;a href=&quot;&#039;. FORUM_ROOT .&#039;viewtopic.php?id=&#039;.$cur_post[&#039;id&#039;].&#039;&quot; title=&quot;View Replies&quot; &gt;&#039;.$cur_post[&#039;num_replies&#039;].&#039; Comments&lt;/a&gt;</code></pre></div><p>links to the post id not to the topic id. How can I fix that?</p>]]></description>
			<author><![CDATA[null@example.com (VincentBroccoli)]]></author>
			<pubDate>Tue, 24 Mar 2009 13:25:38 +0000</pubDate>
			<guid>https://punbb.informer.com/forums/post/126053/#p126053</guid>
		</item>
		<item>
			<title><![CDATA[Re: How do MySQL queries in PunBB work?]]></title>
			<link>https://punbb.informer.com/forums/post/126050/#p126050</link>
			<description><![CDATA[<div class="quotebox"><cite>pepak wrote:</cite><blockquote><p>What&#039;s the problem? Building a real query is hardly any more than concatecating all keys and values into one string.</p></blockquote></div><p>Just because you may be familiar with php and SQL does not mean that everyone is.</p>]]></description>
			<author><![CDATA[null@example.com (MattF)]]></author>
			<pubDate>Tue, 24 Mar 2009 11:22:54 +0000</pubDate>
			<guid>https://punbb.informer.com/forums/post/126050/#p126050</guid>
		</item>
		<item>
			<title><![CDATA[Re: How do MySQL queries in PunBB work?]]></title>
			<link>https://punbb.informer.com/forums/post/126043/#p126043</link>
			<description><![CDATA[<p>Right now we have only one <a href="http://punbb.informer.com/wiki/punbb13/faq#database_helpers">article</a> in wiki, related with DB query.<br />John_S, this query will return the first post of every forum topic with forum_id = 10:<br /></p><div class="codebox"><pre><code> $query = array(
    &#039;SELECT&#039;    =&gt;    &#039;p.id, p.message, t.subject, t.poster, t.num_replies, t.posted, p.poster_id, t.num_replies&#039;,
    &#039;FROM&#039;        =&gt;    &#039;posts AS p&#039;,
    &#039;JOINS&#039;        =&gt; array(
        array(
            &#039;LEFT JOIN&#039;    =&gt;    &#039;topics AS t&#039;,
            &#039;ON&#039;        =&gt;    &#039;p.topic_id = t.id&#039;
        )
    ),
    &#039;WHERE&#039;        =&gt; &#039;p.id = t.first_post_id AND t.forum_id = 10&#039;,
    &#039;ORDER BY&#039;    =&gt; &#039;t.posted DESC&#039;
);    </code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Slavok)]]></author>
			<pubDate>Tue, 24 Mar 2009 09:05:56 +0000</pubDate>
			<guid>https://punbb.informer.com/forums/post/126043/#p126043</guid>
		</item>
		<item>
			<title><![CDATA[Re: How do MySQL queries in PunBB work?]]></title>
			<link>https://punbb.informer.com/forums/post/126036/#p126036</link>
			<description><![CDATA[<p>What&#039;s the problem? Building a real query is hardly any more than concatecating all keys and values into one string.</p>]]></description>
			<author><![CDATA[null@example.com (pepak)]]></author>
			<pubDate>Tue, 24 Mar 2009 05:45:07 +0000</pubDate>
			<guid>https://punbb.informer.com/forums/post/126036/#p126036</guid>
		</item>
		<item>
			<title><![CDATA[Re: How do MySQL queries in PunBB work?]]></title>
			<link>https://punbb.informer.com/forums/post/126028/#p126028</link>
			<description><![CDATA[<p>Anyone? I think there are more people who need a function like this for a website.</p>]]></description>
			<author><![CDATA[null@example.com (VincentBroccoli)]]></author>
			<pubDate>Mon, 23 Mar 2009 22:35:07 +0000</pubDate>
			<guid>https://punbb.informer.com/forums/post/126028/#p126028</guid>
		</item>
		<item>
			<title><![CDATA[Re: How do MySQL queries in PunBB work?]]></title>
			<link>https://punbb.informer.com/forums/post/125948/#p125948</link>
			<description><![CDATA[<p>I have the same question. Is there any way to change the code that John_S posted in a way that the latest new topics from a specific forum will be displayed as news.</p>]]></description>
			<author><![CDATA[null@example.com (VincentBroccoli)]]></author>
			<pubDate>Sat, 21 Mar 2009 00:10:50 +0000</pubDate>
			<guid>https://punbb.informer.com/forums/post/125948/#p125948</guid>
		</item>
		<item>
			<title><![CDATA[Re: How do MySQL queries in PunBB work?]]></title>
			<link>https://punbb.informer.com/forums/post/124854/#p124854</link>
			<description><![CDATA[<p>have a look at <a href="http://fluxbb.org/wiki/v1.3:developing_extensions#databases">http://fluxbb.org/wiki/v1.3:developing_ … #databases</a></p>]]></description>
			<author><![CDATA[null@example.com (Utchin)]]></author>
			<pubDate>Thu, 19 Feb 2009 18:20:49 +0000</pubDate>
			<guid>https://punbb.informer.com/forums/post/124854/#p124854</guid>
		</item>
		<item>
			<title><![CDATA[How do MySQL queries in PunBB work?]]></title>
			<link>https://punbb.informer.com/forums/post/124851/#p124851</link>
			<description><![CDATA[<p>Hello everybody,</p><p>Recently I decided to add some modification to my Punbb installation, but I had to face the fact that I don&#039;t have even a tiniest idea of how SQL queries are working in PunBB.</p><p>So far I tried everything I knew on this query which is supposed to bring first post of a topic created in a specific forum and display it as a news entry. However all I get is that it displays all posts made in that forum.</p><div class="codebox"><pre><code>&lt;?php
define(&#039;FORUM_ROOT&#039;, &#039;forum/&#039;);
require FORUM_ROOT.&#039;include/common.php&#039;;

define(&#039;RECENT_POSTS_SHOW_POST&#039;, true); // Set to false to show topic subject only

$query = array(
    &#039;SELECT&#039;    =&gt; &#039;p.id, p.message, t.subject, t.poster, t.num_replies, t.posted, p.poster_id, t.num_replies&#039;,
    &#039;FROM&#039;        =&gt; &#039;topics AS t&#039;,
    &#039;WHERE&#039;        =&gt; &#039;t.forum_id = 2 AND t.sticky = 0&#039;,
    &#039;JOINS&#039;        =&gt; array(
        array(
            &#039;LEFT JOIN&#039;        =&gt; &#039;posts AS p&#039;,
            &#039;ON&#039;            =&gt; &#039;p.topic_id = t.id&#039;
        )
    ),
    &#039;ORDER BY&#039;    =&gt; &#039;t.posted DESC&#039;,
    &#039;LIMIT&#039;        =&gt; &#039;0,10&#039;
);
 
$result = $forum_db-&gt;query_build($query) or error(__FILE__, __LINE__);
 
$recent_posts = array();
while ($cur_post = $forum_db-&gt;fetch_assoc($result))
    $recent_posts[] = $cur_post;
 
// Print out posts
if (!empty($recent_posts))
{
    foreach($recent_posts as $cur_post)
    {
        $message = str_replace(&quot;\n&quot;, &quot;&lt;br /&gt;&quot;, $cur_post[&#039;message&#039;]);
        $date = date(&quot;j  M  Y&quot;, $cur_post[&#039;posted&#039;]);
        
        echo &#039;
        &lt;h2&gt;&#039;.$cur_post[&#039;subject&#039;].&#039;&lt;/h2&gt;
        &lt;p class=&quot;info&quot;&gt;Written by &lt;a href=&quot;&#039;. FORUM_ROOT .&#039;profile.php?id=&#039;.$cur_post[&#039;poster_id&#039;].&#039;&quot; 
        title=&quot;&#039;.$cur_post[&#039;poster&#039;].&#039;\&#039;s profile&quot;&gt;&#039;.$cur_post[&#039;poster&#039;].&#039;&lt;/a&gt; on &#039;.$date.&#039; | 
        &lt;a href=&quot;&#039;. FORUM_ROOT .&#039;viewtopic.php?id=&#039;.$cur_post[&#039;id&#039;].&#039;&quot; title=&quot;View Replies&quot; &gt;&#039;.$cur_post[&#039;num_replies&#039;].&#039; Comments&lt;/a&gt;&lt;/p&gt;
        &lt;p&gt;&#039;.$message.&#039;&lt;/p&gt;&#039;;
        
    }
}
 else { echo &#039;&lt;p&gt;We are sorry but no news were found in the database, if you believe this is an error, please notify the administrator.&lt;/p&gt;&#039;; }
?&gt;</code></pre></div><p>Could somebody explain it please? I tried searching though the WiKi but there seems to be no articles about it.<br />Thanks a lot in advance! <img src="https://punbb.informer.com/forums/img/smilies/big_smile.png" width="15" height="15" alt="big_smile" /></p>]]></description>
			<author><![CDATA[null@example.com (John_S)]]></author>
			<pubDate>Thu, 19 Feb 2009 17:14:41 +0000</pubDate>
			<guid>https://punbb.informer.com/forums/post/124851/#p124851</guid>
		</item>
	</channel>
</rss>
