On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • Quote from: OpenGeek at Aug 29, 2006, 04:20 PM

    What is contained in the $industries array you are populating with the results of your query before it gets passed into the $objTable->create($industries, $industryHeaders) function?

    Not 100% sure. All I did was copied the snippet (but removed the join section), changed the array names to match the database I already have and altered the row headings. There isn’t much documentation for it yet and I’m not a coder.

    From what I can understand, the array is created near the begining of the code by

    	// if the query was successful, build our table array from the rows
    	while ($row= $this->db->getRow($ds)) {
    		$industries[]= array(
    			'Code'=> stripslashes($row['Code']),
    			'Start'=> stripslashes($row['Start']),
    			'Start'=> stripslashes($row['Start']),
                            'End'=> stripslashes($row['End']),
                            'Course'=> stripslashes($row['Course']),
                            'Location'=> stripslashes($row['Location']),
    		);



      [img]http://www.emanz.ac.nz/assets/images/logo/emanz-icon_16x16.gif[/img] Emergency Management Academy of New Zealand [br] http://www.emanz.ac.nz[br][br]MODx Sandbox Login: sandbox Password: castle [br]
      Admin Sandbox Login: sandbox Password: castle
    • Correct, right after the while loop is closed, do this to display the contents of that array in the page where the snippet is called...

      return ’<pre>’ . print_r($industries, true) . ’</pre>’;

      The pre tags just make it easier to see the real values if they are long and would otherwise wrap on the web page. If you can’t view the result through the page view, do a view source or turn off the styles to see the output more easily.
      • Thanks, it displays:

        Array
        (
            [0] => Array
                (
                     => 
        [Start] =>
        [End] =>
        [Course] =>
        [Location] =>
        )

        )

        <br />Should I assume that the array is empty from this? So its therefore not getting the information from the table in the MySQL database?
          [img]http://www.emanz.ac.nz/assets/images/logo/emanz-icon_16x16.gif[/img] Emergency Management Academy of New Zealand [br] http://www.emanz.ac.nz[br][br]MODx Sandbox Login: sandbox Password: castle [br]
          Admin Sandbox Login: sandbox Password: castle
        • That assumption is most likely correct Briggsy. Double check the sql it’s generating, you can always just return $sql to see what is being executed and then try it against the db in phpMyAdmin or similar.
          • If I use SELECT COUNT(id) FROM modx_courses in phpMyAdmin it returns the correct number of records. I then returned $numRecords on the page which is also correct.

            I’m guessing "if ($ds= $this->db->query($query)){" checks to see of the number of loops = number of records in the specified table in the current database (which is emanz_modx)


            Does "while ($row= $this->db->getRow($ds)) {" mean keep adding the next row until it equals the number of records?

            If so, not sure why the array is not getting populated since there is a row called Code etc.

            // query the total number of possible records for the table
            $query= "SELECT COUNT(id) FROM modx_courses";
            $numRecords= $this->db->getValue($query);
            
            // execute the main table query with MakeTable sorting and paging features
            if ($ds= $this->db->query($query)) {
                // if the query was successful, build our table array from the rows
                while ($row= $this->db->getRow($ds)) {
                    $industries[]= array(
                        'Code'=> stripslashes($row['Code']),
                        'Start'=> stripslashes($row['Start']),
                        'Start'=> stripslashes($row['Start']),
                        'End'=> stripslashes($row['End']),
                        'Course'=> stripslashes($row['Course']),
                        'Location'=> stripslashes($row['Location']),
                    );
                }
            }


            Since it returns the headers in the page, it would imply the query has retruned rows as per below, however they are not put on the page, only the header row is and the pagination.

            // make sure our query of industries has returned rows
            if (is_array($industries)) {
                // create the table header definition with each header providing a link to sort by that field
                $industryTableHeader= array(
                    'Code'=> $objTable->prepareOrderByLink('Code', 'Code'),
                    'Start'=> $objTable->prepareOrderByLink('Start', 'Start'),
                    'End'=> $objTable->prepareOrderByLink('End', 'End'),
                    'Course'=> $objTable->prepareOrderByLink('Course', 'Course'),
                    'Location'=> $objTable->prepareOrderByLink('Location', 'Location'),
                );
              [img]http://www.emanz.ac.nz/assets/images/logo/emanz-icon_16x16.gif[/img] Emergency Management Academy of New Zealand [br] http://www.emanz.ac.nz[br][br]MODx Sandbox Login: sandbox Password: castle [br]
              Admin Sandbox Login: sandbox Password: castle
            • try changin $this to $modx in the snippet code..


                "He can have a lollipop any time he wants to. That's what it means to be a programmer."
              • Thanks Doze, tried changing it but still same result.
                  [img]http://www.emanz.ac.nz/assets/images/logo/emanz-icon_16x16.gif[/img] Emergency Management Academy of New Zealand [br] http://www.emanz.ac.nz[br][br]MODx Sandbox Login: sandbox Password: castle [br]
                  Admin Sandbox Login: sandbox Password: castle
                • did you change all occurances?


                    "He can have a lollipop any time he wants to. That's what it means to be a programmer."
                  • Yea, just to ensure I copied it to notepad and did a search and $this is not found.

                    [edit: I sent you a PM with a login to the admin panel]
                      [img]http://www.emanz.ac.nz/assets/images/logo/emanz-icon_16x16.gif[/img] Emergency Management Academy of New Zealand [br] http://www.emanz.ac.nz[br][br]MODx Sandbox Login: sandbox Password: castle [br]
                      Admin Sandbox Login: sandbox Password: castle
                    • Hi Briggsy, I haven’t used MakeTable as yet but looking at your posted code - the $query is defined as:
                      $query= "SELECT COUNT(id) FROM modx_courses";


                      This is first used to find the total number of records in the table (which is fine) - but, then, this query is also used to form the array. This seems wrong to me (and would explain the single item array which has all empty values, I think)

                      I could be entirely wrong on that one, but I think the problem definitely lies around the actual query to the database.

                      Cheers,
                      Garry
                        Garry Nutting
                        Senior Developer
                        MODX, LLC

                        Email: support@modx.com
                        Twitter: @garryn
                        Web: modx.com