<?xml version="1.0" encoding="UTF-8"?>    <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
      <channel>
        <title>How to do DISTINCT database queries</title>
        <link>https://interactivetools.com/forum/forum-posts.php?How-to-do-DISTINCT-database-queries-69946</link>
        <description></description>
        <pubDate>Fri, 15 May 2026 03:41:50 -0700</pubDate>
        <language>en-us</language>
        <atom:link href="https://interactivetools.com/forum/forum-posts.php?rss=1&amp;How-to-do-DISTINCT-database-queries-69946" rel="self" type="application/rss+xml" />

                <item>
          <title>Re: [Jason] Notice: Undefined offset: 1 in [&apos;DOCUMENT_ROOT&apos;]/CMS/lib/database_functions.php on line 507</title>
          <link>https://interactivetools.com/forum/forum-posts.php?postNum=2217251#post2217251</link>
          <description><![CDATA[Hi Jason,<br /><br />I dont know why but I tried groupBy sentence in getRecords method and didn't work. Now I tried it again and now its works, maybe I typed it wrong [laugh]<br /><br />Thank you!<br />]]></description>
          <pubDate>Wed, 01 Aug 2012 01:19:01 -0700</pubDate>
          <guid isPermaLink="true">forum-posts.php?postNum=2217251#post2217251</guid>
        </item>
                <item>
          <title>Re: [alissibronte] Notice: Undefined offset: 1 in [&apos;DOCUMENT_ROOT&apos;]/CMS/lib/database_functions.php on line 507</title>
          <link>https://interactivetools.com/forum/forum-posts.php?postNum=2217244#post2217244</link>
          <description><![CDATA[Hi,<br /><br />When using mysql_query_fetch_all_assoc, the function will not gather uploads.  This is a function of the getRecords() function.<br /><br />The easiest solution here would be to use getRecords and add in:<br /><br /><code>  'groupBy'  =&gt;  'country',</code><br /><br />Hope this helps<br />]]></description>
          <pubDate>Tue, 31 Jul 2012 12:54:43 -0700</pubDate>
          <guid isPermaLink="true">forum-posts.php?postNum=2217244#post2217244</guid>
        </item>
                <item>
          <title>Re: [Dave] Notice: Undefined offset: 1 in [&apos;DOCUMENT_ROOT&apos;]/CMS/lib/database_functions.php on line 507</title>
          <link>https://interactivetools.com/forum/forum-posts.php?postNum=2217240#post2217240</link>
          <description><![CDATA[Hi!<br /><br />I used the 'mysql_query_fetch_all_assoc' to create a custom query with GROUP BY clause, but I got a problem.<br /><br />This works great:<br /><code>$pressRecords = mysql_query_fetch_all_assoc(&quot;SELECT * FROM {$TABLE_PREFIX}press GROUP BY country&quot;);<br />  foreach ($pressRecords as $record) { <br />    print &quot;title: {$record['title']}&lt;br/&gt;\n&quot;; <br />  }</code><br /><br />but I cant access to Uploads fields like:<br /><code>foreach ($pressRecords as $record):<br />   foreach ($record['images'] as $upload):<br />      &lt;img src=&quot;&lt;?php echo $upload['urlPath']; ?&gt;&quot; alt=&quot;&lt;?php echo $upload['info1']; ?&gt;&quot; /&gt;<br />   endforeach;<br />endforeach;</code><br /><br />What can I do?<br />]]></description>
          <pubDate>Tue, 31 Jul 2012 10:10:35 -0700</pubDate>
          <guid isPermaLink="true">forum-posts.php?postNum=2217240#post2217240</guid>
        </item>
                <item>
          <title>Re: [Dave] Notice: Undefined offset: 1 in [&apos;DOCUMENT_ROOT&apos;]/CMS/lib/database_functions.php on line 507</title>
          <link>https://interactivetools.com/forum/forum-posts.php?postNum=2196879#post2196879</link>
          <description><![CDATA[Dave,<br />Thanks. That is perfect!! <br />The 'mysql_query_fetch_all_assoc()' call worked great!!<br /><br />Thanks again.<br />Doug<br />]]></description>
          <pubDate>Fri, 10 Apr 2009 13:39:23 -0700</pubDate>
          <guid isPermaLink="true">forum-posts.php?postNum=2196879#post2196879</guid>
        </item>
                <item>
          <title>Re: [dougdrury] Notice: Undefined offset: 1 in [&apos;DOCUMENT_ROOT&apos;]/CMS/lib/database_functions.php on line 507</title>
          <link>https://interactivetools.com/forum/forum-posts.php?postNum=2196861#post2196861</link>
          <description><![CDATA[Hi Doug,<br /><br />The simplest way is just to use straight PHP/MySQL as follows (note that you'll need to change the table and  fieldnames.  Also, if you require viewer_functions.php first, it will connect to mysql for you with your mysql login details stored in CMS Builder.  Otherwise you'd need to call mysql_connect().<br /><br /><code>  require_once &quot;../lib/viewer_functions.php&quot;;<br /><br />  $query  = &quot;SELECT DISTINCT title FROM {$TABLE_PREFIX}news&quot;;<br />  $result = mysql_query($query) or die(&quot;MySQL Error: &quot;. htmlspecialchars(mysql_error()) . &quot;\n&quot;);<br />  while ($record = mysql_fetch_assoc($result)) {<br />    print &quot;title: {$record['title']}&lt;br/&gt;\n&quot;;<br />  }<br />  if (is_resource($result)) { mysql_free_result($result); }</code><br /><br />Or if you have a more recent version of CMS Builder you can try this helper function I made to simplify that:<br /><br /><code>  $records = mysql_query_fetch_all_assoc(&quot;SELECT DISTINCT title FROM {$TABLE_PREFIX}news&quot;);<br />  foreach ($records as $record) {<br />    print &quot;title: {$record['title']}&lt;br/&gt;\n&quot;;<br />  }</code><br /><br />Hope that helps!<br />]]></description>
          <pubDate>Thu, 09 Apr 2009 12:18:16 -0700</pubDate>
          <guid isPermaLink="true">forum-posts.php?postNum=2196861#post2196861</guid>
        </item>
                <item>
          <title>Re: [ross] Notice: Undefined offset: 1 in [&apos;DOCUMENT_ROOT&apos;]/CMS/lib/database_functions.php on line 507</title>
          <link>https://interactivetools.com/forum/forum-posts.php?postNum=2196858#post2196858</link>
          <description><![CDATA[Ross,<br />Thanks for this. I am not looking to populate a select field though. I am just trying to select a DISTINCT return from and SQL query and iterate through that list to show an HTML table.<br /><br />In other words, something like a $useDistinct=true; that would convert the SELECT query in CMS builder from:<br /><br />SELECT projectType FROM tablename;<br /><br />to<br /><br />SELECT DISTINCT projectType FROM tablename;<br /><br />...so that I can get only one return per distinct project type.<br />]]></description>
          <pubDate>Thu, 09 Apr 2009 11:12:41 -0700</pubDate>
          <guid isPermaLink="true">forum-posts.php?postNum=2196858#post2196858</guid>
        </item>
                <item>
          <title>Re: [dougdrury] Notice: Undefined offset: 1 in [&apos;DOCUMENT_ROOT&apos;]/CMS/lib/database_functions.php on line 507</title>
          <link>https://interactivetools.com/forum/forum-posts.php?postNum=2196857#post2196857</link>
          <description><![CDATA[Hi Doug<br /><br />This one is going to get a little technical but I do have some code for you to try out. The example I am using will create a drop down menu with all the options from a database field.<br /><br /><code>&lt;select&gt;<br />	&lt;option value=&quot;&quot;&gt;Any&lt;/option&gt;<br />	&lt;?php<br />		$tablename    = 'TABLENAME';<br />		$fieldname    = 'FIELDNAME';<br />		$schema       = loadSchema($tablename);<br />		$fieldSchema  = $schema[$fieldname];<br />		$fieldOptions = getListOptionsFromSchema($fieldSchema);<br />		<br />		foreach ($fieldOptions as $valueAndLabel) {<br />			list($value, $label) = $valueAndLabel;<br />			$encodedValue = htmlspecialchars($value);<br />			$encodedLabel = htmlspecialchars($label);<br />			print &quot;&lt;option value='$encodedValue'&gt;$encodedLabel&lt;/option&gt;\n&quot;;<br />		}<br />	?&gt;<br />&lt;/select&gt;</code><br /><br />You'll need to make sure you include the  /cmsAdmin/lib/viewer_functions.php file on this page if you aren't already.<br /><br />Give it a shot and let me know how you make out. Thanks!<br />]]></description>
          <pubDate>Thu, 09 Apr 2009 11:08:06 -0700</pubDate>
          <guid isPermaLink="true">forum-posts.php?postNum=2196857#post2196857</guid>
        </item>
                <item>
          <title>Re: [Dave] Notice: Undefined offset: 1 in [&apos;DOCUMENT_ROOT&apos;]/CMS/lib/database_functions.php on line 507</title>
          <link>https://interactivetools.com/forum/forum-posts.php?postNum=2196846#post2196846</link>
          <description><![CDATA[I have a cms table called 'projects'. It has a field name 'projectType'. I would like to just get a DISTINCT return of the project types and display them on a page. I will be using this data to create some HTML, not populate a list field on the site or in the cmsAdmin pages.<br /><br />Thanks!!<br />Doug<br />]]></description>
          <pubDate>Wed, 08 Apr 2009 20:25:55 -0700</pubDate>
          <guid isPermaLink="true">forum-posts.php?postNum=2196846#post2196846</guid>
        </item>
                <item>
          <title>Re: [dougdrury] Notice: Undefined offset: 1 in [&apos;DOCUMENT_ROOT&apos;]/CMS/lib/database_functions.php on line 507</title>
          <link>https://interactivetools.com/forum/forum-posts.php?postNum=2196845#post2196845</link>
          <description><![CDATA[Hi Doug,<br /><br />Do you mean as a general query to load some data and display it or to get the values for a list field? What do you want to do with it?<br /><br />Let me know and I'll try and help.<br />]]></description>
          <pubDate>Wed, 08 Apr 2009 19:09:26 -0700</pubDate>
          <guid isPermaLink="true">forum-posts.php?postNum=2196845#post2196845</guid>
        </item>
                <item>
          <title>How to do DISTINCT database queries</title>
          <link>https://interactivetools.com/forum/forum-posts.php?postNum=2196844#post2196844</link>
          <description><![CDATA[Hey Dave,<br />Sort of on topic...<br />is there anyway to use the CMS Builder database_functions.php to send a DISTINCT query to the database?<br /><br />Thanks,<br />Doug<br /><br />Moderator Edit: Detached and renamed thread.<br />]]></description>
          <pubDate>Wed, 08 Apr 2009 19:03:42 -0700</pubDate>
          <guid isPermaLink="true">forum-posts.php?postNum=2196844#post2196844</guid>
        </item>
              </channel>
    </rss>
  