User Tools

Site Tools


en:dev:all:examples:sql

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:dev:all:examples:sql [16.07.2015 22:08] – finished translation and removed fixme mrbasemanen:dev:all:examples:sql [20.02.2019 07:49] (current) – [SELECT] Manuela v.d.Decken
Line 16: Line 16:
 Each of all the four examples give back a result-object with all records of the visible sections of a page at the current time. Each of all the four examples give back a result-object with all records of the visible sections of a page at the current time.
 <code php Example-1.php>  <code php Example-1.php> 
-$oResult = $oDb->doQuery("SELECT section_id, page_id, position, module, block, publ_start, publ_end FROM ".TABLE_PREFIX."sections where page_id= $iPageId and (publ_start = 0 OR publ_start <= $iTimestamp and (publ_end = 0 OR publ_end >= $iTimestamp ) order by block, position");+$oResult = $oDb->doQuery("SELECT section_id, page_id, position, module, block, publ_start, publ_end FROM ".TABLE_PREFIX."sections where page_id= $iPageId and $iTimestamp between `publ_start` and `publ_endorder by block, position");
 </code> </code>
 <code php Example-2.php>  <code php Example-2.php> 
 $sql  = 'SELECT `section_id`, `page_id`, `position`, `module`, `block`, `publ_start`, `publ_end` FROM `'.$oDb->TablePrefix.'sections` '; $sql  = 'SELECT `section_id`, `page_id`, `position`, `module`, `block`, `publ_start`, `publ_end` FROM `'.$oDb->TablePrefix.'sections` ';
-$sql .= 'WHERE `page_id`='.$iPageId.' AND (`publ_start`=0 OR `publ_start`<='.$iTimestamp.') AND (`publ_end`=0 OR `publ_end`>='.$iTimestamp.'';+$sql .= 'WHERE `page_id`='.$iPageId.' AND '.$iTimestamp.' BETWEEN `publ_startAND `publ_end` ';
 $sql .= 'ORDER BY `block`, `position`'; $sql .= 'ORDER BY `block`, `position`';
 $oResult = $oDb->doQuery($sql); $oResult = $oDb->doQuery($sql);
Line 29: Line 29:
      . 'FROM `'.$oDb->TablePrefix.'sections` '      . 'FROM `'.$oDb->TablePrefix.'sections` '
      . 'WHERE `page_id`='.$iPageId.' '      . 'WHERE `page_id`='.$iPageId.' '
-            'AND (`publ_start`=0 OR `publ_start`<='.$iTimestamp.') ' +            'AND '.$iTimestamp.' BETWEEN `publ_startAND `publ_end` '
-            'AND (`publ_end`=0 OR `publ_end`>='.$iTimestamp.''+
      . 'ORDER BY `block`, `position`';      . 'ORDER BY `block`, `position`';
 $oResult = $oDb->doQuery($sql);      $oResult = $oDb->doQuery($sql);     
Line 37: Line 36:
 $sql = 'SELECT * FROM `'.$oDb->TablePrefix.'sections` ' $sql = 'SELECT * FROM `'.$oDb->TablePrefix.'sections` '
      . 'WHERE `page_id`='.$iPageId.' '      . 'WHERE `page_id`='.$iPageId.' '
-            'AND (`publ_start`=0 OR `publ_start`<='.$iTimestamp.') ' +            'AND '.$iTimestamp.' BETWEEN `publ_startAND `publ_end` '
-            'AND (`publ_end`=0 OR `publ_end`>='.$iTimestamp.''+
      . 'ORDER BY `block`, `position`';      . 'ORDER BY `block`, `position`';
 $oResult = $oDb->doQuery($sql);      $oResult = $oDb->doQuery($sql);     
 </code>Let's have a short quiz now:\\ </code>Let's have a short quiz now:\\
-Question: Which of the examples are easier to read, to understand and to modify if required? **1**&**2**  or **3**&**4** ??+**Question:** Which of the examples are easier to read, understand and modify if required?\\ 
 +**Answers:** **1**&**2**  or **3**&**4** ??
 ---- ----
  
en/dev/all/examples/sql.1437084531.txt.gz · Last modified: 16.07.2015 22:08 by mrbaseman