mysql_assign exists NO MORE
authorPierre Habouzit (MadCoder <pierre.habouzit@m4x.org>
Sat, 8 Jan 2005 12:21:37 +0000 (12:21 +0000)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Thu, 26 Jun 2008 21:27:16 +0000 (23:27 +0200)
git-archimport-id: opensource@polytechnique.org--2005/platal--mainline--0.9--patch-240

htdocs/advanced_search.php
htdocs/search.php
include/xorg/database.inc.php
include/xorg/page.inc.php
templates/search.tpl

index 608fd63..88cc9d3 100644 (file)
@@ -127,8 +127,9 @@ if (!Env::has('rechercher')) {
                        .implode(',',array_filter(array($fields->get_order_statement(), 'promo DESC, NomSortKey, prenom'))).'
                 LIMIT  '.$offset->value.','.$globals->search->per_page;
 
-    $page->mysql_assign($sql, 'resultats', 'nb_resultats','nb_resultats_total');
-    $nb_tot  = $page->get_template_vars('nb_resultats_total');
+    $page->assign('resultats', $globals->xdb->iterator($sql));
+    $res     = $globals->xdb->query("SELECT  FOUND_ROWS()");
+    $nb_tot  = $res->fetchOneCell();
     $nbpages = ($nb_tot - 1)/$globals->search->per_page;
 
     $url_ext = Array(
@@ -144,6 +145,7 @@ if (!Env::has('rechercher')) {
     $page->assign('url_short', $url_short);
     $page->assign('url_args',  $url_args);
     $page->assign('perpage',   $globals->search->per_page);
+    $page->assign('nb_tot',    $nb_tot);
     
     if (empty($nb_tot)) {
         form_prepare();
index 67fba51..1e684a5 100644 (file)
@@ -59,9 +59,10 @@ if (Env::has('quick')) {
                        .implode(',',array_filter(array($fields->get_order_statement(), 'u.promo DESC, NomSortKey, prenom'))).'
                 LIMIT  '.$offset->value.','.$globals->search->per_page;
 
-    $page->mysql_assign($sql, 'resultats', 'nb_resultats','nb_resultats_total');
-    $nb_total = $page->get_template_vars('nb_resultats_total');
-    $nbpages  = ($nb_total-1)/$globals->search->per_page;
+    $page->assign('resultats', $globals->xdb->iterator($sql));
+    $res     = $globals->xdb->query("SELECT  FOUND_ROWS()");
+    $nb_tot  = $res->fetchOneCell();
+    $nbpages  = ($nb_tot-1)/$globals->search->per_page;
 
     $url_ext = Array(
         'mod_date_sort' => Env::has('mod_date_sort')
@@ -70,12 +71,13 @@ if (Env::has('quick')) {
     $page->assign('offsets',  range(0, $nbpages));
     $page->assign('url_args', $fields->get_url($url_ext));
     $page->assign('perpage',  $globals->search->per_page);
+    $page->assign('nb_tot',   $nb_tot);
     
-    if (!logged() && $nb_total > $globals->search->public_max) {
+    if (!logged() && $nb_tot > $globals->search->public_max) {
        new ThrowError('Votre recherche a généré trop de résultats pour un affichage public.');
-    } elseif ($nb_total > $globals->search->private_max) {
+    } elseif ($nb_tot > $globals->search->private_max) {
         new ThrowError('Recherche trop générale');
-    } elseif (empty($nb_total)) {
+    } elseif (empty($nb_tot)) {
         new ThrowError('il n\'existe personne correspondant à ces critères dans la base !');
     }
 
index 18941ff..f7bdfef 100644 (file)
@@ -122,7 +122,11 @@ class XOrgDBResult
     function XOrgDBResult($query)
     {
         global $globals;
-        $this->_res =& $globals->db->query($query);
+        if (strpos("SQL_CALC_FOUND_ROWS", $query) === false) {
+            $this->_res = $globals->db->query($query);
+        } else {
+            $this->_res = mysql_query($query);
+        }
     }
 
     // }}}
index d4e0e68..91dbce5 100644 (file)
@@ -183,45 +183,6 @@ class XorgPage extends DiogenesCorePage
     function doAuth() { }
     
     // }}}
-    // {{{ function mysql_assign()
-
-    function mysql_assign($sql_query,$var_name,$var_nb_name='',$var_found_rows='') {
-        global $globals;
-        //lorsqu'on désire obtenir found_rows il faut désactiver la trace du résultat
-        $switch_trace = false;
-        if (!empty($var_found_rows) && $globals->db->_trace==1) {
-            $switch_trace = true;
-            $globals->db->trace_off();
-        }
-        
-        $sql = $globals->db->query($sql_query);
-        if (mysql_errno()) {
-            return(mysql_error($sql));
-        }
-
-        $array = Array();
-        while ($array[] = mysql_fetch_assoc($sql));
-        array_pop($array);
-        mysql_free_result($sql);
-        $this->assign_by_ref($var_name,$array);
-        if (!empty($var_nb_name)) {
-            $this->assign($var_nb_name, count($array));
-        }
-        
-        if (!empty($var_found_rows)) {
-            $res = $globals->xdb->query('SELECT FOUND_ROWS()');
-            $this->assign($var_found_rows, $res->fetchOneCell());
-            //si la trace était activée on affiche la trace sur la requête initiale
-            if ($switch_trace) {
-                $globals->db->trace_on();
-                $sql = $globals->db->query($sql_query);
-                mysql_free_result($sql);
-            }
-        }
-        return 0;
-    }
-
-    // }}}
     // {{{ function loadModule()
     
     function loadModule($modname)
index 0cd1564..29cbc8b 100644 (file)
   {/if}
 
   <h1 class='right'>
-    {if $nb_resultats_total==0}Aucune{else}{$nb_resultats_total}{/if} réponse{if $nb_resultats_total>1}s{/if}.
+    {if $nb_tot==0}Aucune{else}{$nb_tot}{/if} réponse{if $nb_tot>1}s{/if}.
   </h1>
 
   <div class="contact-list" style="clear:both">
     {capture name=list}
-    {section name=resultat loop=$resultats}
-        {if $resultats[resultat].contact || $resultats[resultat].watch}
-        {assign var="show_action" value="retirer"}
+    {iterate item=res from=$resultats}
+      {if $res.contact || $res.watch}
+        {include file=include/minifiche.tpl c=$res show_action="retirer"}
       {else}
-        {assign var="show_action" value="ajouter"}
+        {include file=include/minifiche.tpl c=$res show_action="ajouter"}
       {/if}
-      {include file=include/minifiche.tpl c=$resultats[resultat] show_action=$show_action}
-    {/section}
+    {/iterate}
     {/capture}
     {$smarty.capture.list|smarty:nodefaults}
   </div>
 
-  {if $perpage < $nb_resultats_total}
+  {if $perpage < $nb_tot}
   <p>
     {if $offset!=0}
     <a href="{$smarty.server.PHP_SELF}?{$url_args}&amp;offset={$offset-$perpage}">Précédent</a>
@@ -58,7 +57,7 @@
       {/if}
       &nbsp;
     {/section}
-    {if $offset < $nb_resultats_total-$perpage}
+    {if $offset < $nb_tot-$perpage}
     <a href="{$smarty.server.PHP_SELF}?{$url_args}&amp;offset={$offset+$perpage}">Suivant</a>
     &nbsp;
     {/if}