[TYPO3-english] a question about exec_SELECTquery()

Luming Xing xingluming at googlemail.com
Wed Jan 7 22:18:42 CET 2009


Hello veryone,
I writing a FE Extension with search funtion. and I am a little confuse 
by the  exec_SELECTquery().

I use HTML template, this is my exec_SELECTquery().
        $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
          '*',   #select
          'tx_modatest_tabledozent', #from
          'first_name='.$this->piVars['firstname'],  #where
          *#'first_name=0',    #where*
          '',
          '',
          '');
when first_name = piVars['firstname'] , it gaves me nothing return.  
but  when first_name = 0, it gaves me the whole data of that table back. 
This is very strange**
am i wrong at this exec_SELECTquery(), or somewhere else?  please help. 
thank you!


**


the following is code of template and PHP class.
**

<!-- ###SEARCHVIEW### -->
<h2>Search</h2>
<form action="###ACTION_URI###" id="form1" name="form1" method="post">
  <table width="478" border="1">
    <tr>
      <td width="114">&nbsp;</td>
      <td width="257"><div align="center">Search</div></td>
      <td width="85">&nbsp;</td>
    </tr>
    <tr>
      <td>First name</td>
      <td><label>
        <input type="text" name="tx_modatest_pi1[firstname]" 
id="firstname" />
      </label></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>Pflicht oder Fwpf</td>
      <td><label>
        <select name="tx_modatest_pi1[pflichtoderfwpf]" 
id="pflichtoderfwpf">
        <!-- ###ROW### -->
          ###PROTYPE###
        <!-- ###ROW### -->
        </select>
      </label></td>
      <td>&nbsp;</td>
    </tr>
    <!--<tr>
      <td>Dozent</td>
      <td><label>
          <select name="Dozent" id="Dozent">
          </select>
      </label></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>Sprache</td>
      <td><label>
        <select name="Sprache" id="Sprache">
        </select>
      </label></td>
      <td>&nbsp;</td>
    </tr>-->
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td><input type="submit" name="startsearch" id="startsearch" 
value="start search" /></td>
    </tr>
  </table>
  <p>&nbsp;</p>
</form>
<!-- ###SEARCHVIEW### -->


<!-- ###DETAILVIEW### -->
<h2>Detailansicht</h2>
<table valign=top border="1">
  <tr>
    <td>Title</td>
    <td>|</td>
    <td>First name</td>
    <td>|</td>
    <td>Last name</td>
  </tr>
  <tr>
    <td colspan="7">----------------------------------</td>
  </tr>
   <!-- ###CONTENT### -->
    <!-- ###ITEM### -->
     <tr>
      
<td>###MARKER1###</td><td>|</td><td>###MARKER2###</td><td>|</td><td>###MARKER3###</td>
     </tr>
    <!-- ###ITEM### -->
   <!-- ###CONTENT### -->

</table>
<!-- ###DETAILVIEW### -->


**

<?php

require_once(PATH_tslib.'class.tslib_pibase.php');

class tx_modatest_pi1 extends tslib_pibase {
    var $prefixId = 'tx_modatest_pi1';        // Same as class name
    var $scriptRelPath = 'pi1/class.tx_modatest_pi1.php';    // Path to 
this script relative to the extension dir.
    var $extKey = 'moda_test';    // The extension key.
    var $pi_checkCHash = TRUE;

    function main($content,$conf)    {
        $this->conf=$conf;
        $this->pi_setPiVarDefaults();
        $this->pi_loadLL();
       
        #ein paar Vorbelegungen
        $this->id=$GLOBALS['TSFE']->id;
        
$this->template=$this->cObj->fileResource('EXT:moda_test/template.html');
       
       
        #welche Ansicht?
        if($this->piVars['firstname']) {
            $content = $this->detailView();
        } else {
            $content = $this->searchView();
        }
   
        return $this->pi_wrapInBaseClass($content);
    }
   
    function searchView() {
        
$subpart=$this->cObj->getSubpart($this->template,'###SEARCHVIEW###');
        $singlerow=$this->cObj->getSubpart($subpart,'###ROW###');
       
        $markerArray['###ACTION_URI###'] = 
htmlspecialchars($this->pi_getPageLink($GLOBALS["TSFE"]->id));
   
        $res=$GLOBALS['TYPO3_DB']->exec_SELECTquery(
        '*',   #select
        'tx_modatest_tabledozent', #from
        'pid='.intval($this->id),  #where
        $groupBy='',
        $orderBy='',
        $limit='');
       
        if($res) {
            $liste='';
            while($row=$GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))
            {
                $markerArray['###PROTYPE###']='<option 
value="456">'.$row['first_name'].'</option>';
                $liste .= 
$this->cObj->substituteMarkerArrayCached($singlerow,$markerArray);
            }
           
            $subpartArray['###ROW###']=$liste;
        } else {
            return $this->pi_getLL('nodata');
        }
       
        $GLOBALS['TYPO3_DB']->sql_free_result($res);
       
        return 
$this->cObj->substituteMarkerArrayCached($subpart,$markerArray,$subpartArray,'');  

    }
   
   
   
    function detailView() {

         $template['total'] = 
$this->cObj->getSubpart($this->template,'###DETAILVIEW###');
         $template['item'] = 
$this->cObj->getSubpart($template['total'],'###ITEM###');
          
        $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
          '*',   #select
          'tx_modatest_tabledozent', #from
          'first_name='.$this->piVars['firstname'],  #where
          #'first_name=0',    #where
          '',
          '',
          '');
         
          if($res) {
                       // Loop through query result
                        while ($row = 
$GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
                            // Fill marker
                               $markerArray['###MARKER1###'] = 
$row['title'];            
                               $markerArray['###MARKER2###'] = 
$row['first_name'];
                               $markerArray['###MARKER3###'] = 
$row['last_name'];
          
                             // Add subpart into a string
                               $content_item .= 
$this->cObj->substituteMarkerArrayCached($template['item'], $markerArray);
                      }  
          
                // Fill subpart marker
              $subpartArray['###CONTENT###'] = $content_item;
          
          }else{
             return $this->pi_getLL('nodata');
         }
          
          $GLOBALS['TYPO3_DB']->sql_free_result($res);
          
            // Finalize and create the content by replacing the 
"content" marker in the template 
          return 
$this->cObj->substituteMarkerArrayCached($template['total'], '', 
$subpartArray);

    }
   
}



if (defined('TYPO3_MODE') && 
$TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/moda_test/pi1/class.tx_modatest_pi1.php'])    
{
    
include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/moda_test/pi1/class.tx_modatest_pi1.php']);
}

?>




More information about the TYPO3-english mailing list