We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1373
    • 12 Posts
    @svarga:
    try to replace ’=’ with ’_eq_’ in the query.
    See the readme file.
      • 813 ☆ A M B ☆
      • 326 Posts
      I love this snippet and use it extensively. However, I’d really like a "No records found" message to show when nothing is returned from the MySQL query. What would I need to modify to do this?

      Thanks!
        • 813 ☆ A M B ☆
        • 326 Posts
        Never mind -- figured it out! In the LoopDBChunk.php file, around line 215, after this line:

        $numRows = $modx->db->getRecordCount($rs);


        add this:

        if($numRows == 0) {
        			$output .= 'No records found.';
        		}
          • 14214
          • 299 Posts
          I like the potential of this Snippet. It is installed and pulls my data how I want. However I need to extend it and would like a little help.

          Basically I would like to accomplish what this page is doing: http://www.w3schools.com/PHP/php_ajax_database.asp

          A second issue is the pagination. Displays correctly however, the links take me to the home page. Pagination in ditto works fine but not sure why it doesn’t here.

          Appreciate the help.
            • 14214
            • 299 Posts
            Any one have an answer or some advice here?
              • 14214
              • 299 Posts
              Bump...
                • 1512
                • 57 Posts
                I’ve just started playing with the loopDbChunk v1.2 snippet, but want it to get the table ’images’ from an external database. I’ve altered the code of LoopDBChunk.php (line 184 onwards) for the renderChunks() function.

                function renderChunks() 
                	{
                		global $modx;
                		require_once("Pagination.php");
                		
                		$query = '';
                		$rs = '';
                		$output = $this->header;
                		
                		$pageStart = $this->getPageStart();
                		
                		if($this->sql != '') 
                		{
                			$query = str_replace('_eq_', '=', $this->sql);
                		}
                		else 
                		{
                			$fields = implode(',', array_unique($this->fieldNames));
                         $query = 'SELECT ' . $fields . ' FROM ' . $this->tableName;
                			if ($this->orderby != '') {
                				$query .= ' ORDER BY ' . $this->orderby;
                			}
                		}	
                		
                		$rs = $modx->db->connect('localhost', 'database', 'user', 'password', true);
                		$rs = $modx->db->query($query);
                		$numRows = $modx->db->getRecordCount($rs);
                		
                		if($this->perPage > 0) 
                		{
                   		$from = $pageStart - 1;
                   		$query .= ' LIMIT ' . $from . ', ' . $this->perPage;
                   	}


                However, now the whole page explodes

                « MODx Parse Error »

                MODx encountered the following error while attempting to parse the requested resource:
                « Execution of a query to the database failed - SELECT command denied to user ’account_user’@’localhost’ for table ’cms_site_tmplvars’ »
                SQL: SELECT tv.*, IF(tvc.value!=’’,tvc.value,tv.default_text) as value FROM `main_db`.`cms_site_tmplvars` tv INNER JOIN `main_db`.`cms_site_tmplvar_templates` tvtpl ON tvtpl.tmplvarid = tv.id LEFT JOIN `main_db`.`cms_site_tmplvar_contentvalues` tvc ON tvc.tmplvarid=tv.id AND tvc.contentid = ’11426’ WHERE tv.name IN (’id’) AND tvtpl.templateid = 90
                [Copy SQL to ClipBoard]

                and on and on. So it looks like the connect to external db is being used by every aspect of this page and not just the chunk.

                Any advice?

                Cheers
                  • 14214
                  • 299 Posts
                  How can I post a search to my loopDbChunk call?

                  &sql=`SELECT * from tableName WHERE column LIKE ’[*user-submitted-data*]’`

                  I would like to do this either via a dropdown list fed from the table column being searched or via a user search box.

                  Any advice?
                    • 18913
                    • 654 Posts
                    @andre : If I understand what you’re doing correctly, you need to replace the MODx database calls with their equivalent php/MySQL calls.

                    Matt
                      • 27442
                      • 103 Posts
                      The problem with pagination & friendly URLs seems to be the virtual folder path.

                      www.site.example/table.html?pagestart=26 (or whatever) seems to work fine but

                      www.site.example/folder/table.html?pagestart=26 (or whatever) will not.

                      It appears that when the page links are generated, only the alias is used, not the ’path’\alias. Unfortunately, I’m not good enough with this stuff to figure out how to fix it.