php - get values ​​from a query of a class -


i developed class paging url friendly, problem can not pull array variable define values ​​of database

private function query($page){      $u = url::geturl($page);     $numreg = $this->max_reg; // quantos registros por página vai ser mostrado      if (!isset($u)) {         $u = 1;     }      @$inicial = $u * $this->max_reg;     $sql = mysql_query("select * {$this->table} order id desc limit $inicial, $numreg") or die(mysql_error());               $sql_conta = mysql_query("select * {$this->table}") or die(mysql_error());      $out = '';      while ($data = mysql_fetch_array($sql_conta)) {                  $out.= $this->html;          }      return print $out;       } 

so far working

problem :

global $data; $p = new pagination; $p->html    = '                         <li>                              <div class="clbthumb"><a href="#"><img src="asset/images/noticias/news4.gif" alt="" /></a></div>                             <div class="clbdes">                                 <p class="clbtitle"><a class="colr4" href="#">'.$data['titulo'].'</a></p>                                   <p>'.$data['texto'].'</p>                                 <div class="clear"></div>                                 <div class="clbinfo">                                     <ul>                                         <li class="datetag">                                             <span class="colr3">data:</span>                                              <span class="pink padr">tue, 26/01/11</span>                                          <li class="moreinfo"><a href="#">:: ler mais</a></li>                                      </ul>                                 </div>                             </div>                         </li>'; $p->af_html = '                     </ul>                 </div>'; $p->_build(2); 

is there method this?

you cannot access variable assigned inside class outside such way. $data variable in usage (assigned html) not accessible (in second section of code).

if insist set html outside of class, can add place holders html each variable , replace them inside class.

so code

(assuming class pagination)  class pagination     private function query($page){          ...         while ($data = mysql_fetch_array($sql_conta)) {                      $out.= str_replace('##data_titulo##', $data['titulo'] , $this->html, $out);             $out.= str_replace('##data_texto##', $data['texto'] , $this->html, $out);         }         ...     } } 

and second part

$p = new pagination; $p->html    = '... <a class="colr4" href="#">##data_titulo##</a></p>  <p>##data_texto##</p>...'; 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -