select() function

returns a result set based on WHERE criteria

Parameters - select( tablename, where, select, sort, limit )
  1. SQL table name
  2. WHERE condition - array, multiple values treated as AND parameters
      e.g. WHERE col1 = value1 AND col2 = value2
  3. SELECT arguments - comma-delimited string, defaults to *
  4. SORT argument - array,  i.e. ORDER BY
  5. LIMIT argument - integer, default to 9999

Example 1: select() MVC Show Process

  1. trigger a display event (Javascript)
  2. invoke a PHP function with select() data result being (render) to html page/view
  3. data being process within page/view (HTML)

    // Example 1   [public/mvcspa/controller]   SHOW PROCESS
    //    Javascript load PHP showClass result into [sharktank] div

    $(document).on('click', "a#showclass",
    function (e) {
        e.preventDefault();

        $('#sharktank').load('controller/showclass');  // invokes PHP controller function
    });

    // Example 1   [controllers/controller] - PHP showClass function

    function showClass() {
        $this->view->rs_class  = = $this->model->db->select('class');  // returns entire table result set
        $this->view->render('controller/showclass', false);   // invokes view markup file
    }

    // Example 1   [views/showclass] - embedded HTML below loops thru $rs_class result set

    <?php
    // foreach fetches a row as it loops
    foreach ( $this->rs_class as $row ) :
    ?>
        /** HTML markup here processes ($row) data to format and display output **/
    <?php endforeach; ?>
    
    // Example 2    rowCount() of result set
    $orgid  = (int) Session::get('orgid');
    $col2   = $_POST['col2'];

    $WHERE = array();
    $WHERE['orgid'] = $orgid;
    $WHERE['col2']  = $col2;
    $rs_table = $this->model->db->select('table', $WHERE, $sel='*' );
    $alertCount = $rs_table->rowCount(); // PDO, returns rows in result set
    if ( $alertCount )
        echo($alertCount);