Author Topic: Need help with Array Logic  (Read 56 times)

0 Members and 1 Guest are viewing this topic.

Offline RovchTopic starter

  • Irregular
  • Posts: 2
    • View Profile
Need help with Array Logic
« on: January 30, 2012, 06:25:35 AM »
Hey guys,

I've trying to edit some elses array, but no luck.
Right now it shows current and next month.
Needs to show next and one after the next.

I am pretty new to PHP, and I hope I can get some help here.

Main code:

Code: [Select]
<?php 
$oneMonth 
VarsItem::getVarsValue('oneMonthTravel'); 
$oneMonth == ($oneMonth == '') ? $oneMonth
$monthAll TravelItem::getAllMount(array('limit' => 2'start' => $oneMonth)); 
if (
sizeof($monthAll) > 0

  
$i 0?>

  <table border="0" cellspacing="0" cellpadding="0" width="520" align="center">
    <tr valign="top">
      <td width="100%"><img src="/image/0.gif" width="1" height="15" border="0" /></td> 
    </tr>
    </table>
    <a name="inquirer"></a>
    <table border="0" cellspacing="0" cellpadding="0" width="520" align="center">
    <tr valign="top">
      <td align="center" colspan="2"><img src="/image/where.gif" width="505" height="16" border="0" /></td>
    </tr>
    <tr valign="top">
      <?
       
      foreach ($monthAll as $onemonth)
      {
       
        $i++; 
            ?>
        <td width="260">
          <table border="0" cellspacing="0" cellpadding="0" width="100%" class="latestmain">
            <tr><td colspan="2"><h3><%= strtoupper(monthAll($onemonth["month_id"],'namer')) %></h3></td></tr>
            <?
            $rowTravel = TravelItem::SelectAll(array('month_id' => $onemonth["month_id"], 'is_show' => 1));
            foreach ($rowTravel as $onerowTravel)
            { 
              $style ='style="padding-left:5px;"';
              $partArray = checkEmptyPartitions($part, CountryItem::getCountryWorkName($onerowTravel['country_id']));
              $hrefTravel = CountryItem::getCountryWorkName($onerowTravel['country_id'])."/".(($partArray["$part"] == 1) ? $part.'/' : ""); ?>
              <tr valign="top">
                <td><img src="/image/bullet-a.gif" width="9" height="9" border="0" style="margin-top:2px;" /></td>
                <td width="100%" <%= $style %>><b><span id="orange"><%= CountryItem::getCountryName($onerowTravel['country_id']) %>:</span></b> <small><%= $onerowTravel['title'] %>  <a href="<%= $hrefTravel %>">details...</a></small></td>
              </tr>
              <?
           }  ?>
          </table>
        </td>
        <?
      } ?>
    </tr>
    <tr valign="top">
      <td colspan="<%= $i+1 %>">
        <table border="0" cellspacing="0" cellpadding="0" width="100%" class="latestmain">
          <tr><td><a href="travel.htm">where else to go</a></td></tr>
        </table>
      </td>   
    </tr>
  </table>
  <?
} ?>

And TravelItem class:

Code: [Select]
<?php 
class TravelItem extends Storable 

   function 
TravelItem($row = array()) {  
      
Storage::Init(TravelItem::def(), $this->data); 
      
$this->Storable($row);  
   } 


   function &
def() { 
      return array( 
         
'fields' => array( 
            
'travel_id'  => 0
            
'month_id'   => 0
            
'country_id' => 0
            
'title'      => '',  
            
'ord'        => ''
            
'is_show'    => 1
             
         ), 
         
'key'      => 'travel_id'
         
'auto_key' => true
         
'auto_update' => array('is_show' => 0), 
         
'table'    => 'travel'); 
   } 


   function &
Load($id) {  
      if (!(
$row =& Storage::Load(TravelItem::def(), $id))) return false
      return new 
TravelItem($row); 
   } 

  
   function 
Store() { 
     
$actionMail = ($this->data['travel_id'] > 0) ? 'edit' 'add'
     
$templateMail 'travel'
     if (
Storage::Store(TravelItem::def(), $this->data)) {   
       
changeSite($actionMail,$templateMail,$this->data['travel_id']); 
       return 
true
     } else return 
false;    
   } 
    

   function 
Update(&$rows) {  
     
$actionMail 'update'
     
$templateMail 'travel'
     
changeSite($actionMail,$templateMail,$rows); 
     return 
Storage::Update(TravelItem::def(), $rows);  
   } 

  
   function 
Delete(&$ids)  { 
     
$actionMail 'delete'
     
$templateMail 'travel'
     
changeSite($actionMail,$templateMail,$ids); 
     return 
Storage::Delete(TravelItem::def(), $ids); 
   } 
    
   function 
getWhere(&$parms) { 
    
$where ""
    if (isset(
$parms['month_id'])) $where "month_id='".$parms['month_id']."'"
    if (isset(
$parms['country_id'])) $where = (empty($where) ? "" $where." and ")."country_id='".$parms['country_id']."'"
    if (isset(
$parms['is_show'])) $where = (empty($where) ? "" $where." and ")."is_show='".$parms['is_show']."'"
    if (isset(
$parms['searchFilter'])) $where = (empty($where) ? "" $where." and ")."title LIKE '%".$parms['searchFilter']."%'"
    
$where = empty($where) ? "" "WHERE ".$where
    return 
$where
  } 
   
  function 
getOrder(&$parms) { 
    
$field "month_id,ord*100,country_id"
    if (isset(
$parms['sort_field']) and !empty($parms['sort_field'])) { $field $parms['sort_field']; } 
    return 
"ORDER BY $field"
  } 

  function 
SelectAll($parms = array()) { 
    
$db =& Storage::DBI(); 
    return 
$db->query("SELECT * FROM travel ".TravelItem::getWhere($parms)." ".TravelItem::getOrder($parms), DBI::ExtractDBParms($parms, array('key' => 'travel_id'))); 
  } 
   
  function 
CountAll($parms = array()) { 
    
$db =& Storage::DBI(); 
    return 
$db->queryValue("SELECT COUNT(*) FROM travel ".TravelItem::getWhere($parms)); 
  } 
   
  function 
getAllMount($parms = array()) 
  { 
    
$limit = (isset($parms['limit'])) ? 'LIMIT '.$parms['limit'] : ''
    
$where = (isset($parms['start'])) ? ' and month_id >= '.$parms['start'] : ''
    if (
$parms['start'] == 12)  $where .= ' or month_id = 1'// for december 
    
$db =& Storage::DBI(); 
    return 
$db->query("SELECT DISTINCT month_id from travel WHERE is_show=1 ".$where." ORDER BY 1 ".($parms['start'] == 12 'DESC' '')." ".$limit); 
  } 
   
  function 
getTitle($travel_id) { 
     
$db =& Storage::DBI(); 
     list(
$country_id,$month_id) = $db->queryList("SELECT country_id,month_id FROM travel WHERE travel_id =?",array("",""),Array($travel_id)); 
     return (
$month_id monthAll($month_id,'namer') : "")." : ".CountryItem::getCountryName($country_id); 
  }  
   
  function 
getUpdateList($travel_id) {  
     
$db =& Storage::DBI(); 
     return 
$db->queryList("SELECT is_show,ord,country_id,month_id FROM travel WHERE travel_id =?",array('','','',''),Array($travel_id)); 
  } 

?>

I've tried adding +1 to $oneMonth and it did not work.
I've also tried skipping first month and increasing array limit to three, but then it only outputs one month instead of two.
And neither worked properly.

Thanks in advance.

Offline RovchTopic starter

  • Irregular
  • Posts: 2
    • View Profile
Re: Need help with Array Logic
« Reply #1 on: January 31, 2012, 08:00:27 PM »
Any help? I've been trying to fix this array for a while.