...

View Full Version : Trying to fix an array



RomanTaylor
01-14-2012, 12:09 PM
Hey guys, I need some assistance here.

Long story short is that I need to edit this array.
Right now it shows current and next month.
Needs to show next and one after the next.

I've tried using array_slice to skip the first month in the array, however then it only shows one month instead of two.

I need some help since someone else wrote this page and I don't completely understand why my logic did not work.


<?php
$oneMonth = VarsItem::getVarsValue('oneMonthTravel');
$oneMonth == ($oneMonth == '') ? 1 : $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>
<?
} ?>

Thank you in advance.

12k
01-14-2012, 05:09 PM
Any chance you can post the TravelItem class. I can't see the code behind it, but it appears that the way it is designed is the following:



$monthAll = TravelItem::getAllMount(array('limit' => 2, 'start' => $oneMonth));


With 2 = how many months to go after the $oneMonth.

So if $oneMonth = 1 (january), it would go 2 additional. Feb (2), and March (3)

But in order to verify that I would have to see the class code.

RomanTaylor
01-15-2012, 08:34 PM
Any chance you can post the TravelItem class.

Yes, sir:


<?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 > 0 ? 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));
}
}
?>

12k
01-16-2012, 03:33 AM
Yupp, what I said should work perfectly fine.

RomanTaylor
01-16-2012, 10:13 AM
Yupp, what I said should work perfectly fine.

So what do I do in this situation?

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.

It thought it's logical, but I am pretty new to PHP and can't seem to get this to work properly.

12k
01-16-2012, 01:31 PM
So you have tried to change this:



$monthAll = TravelItem::getAllMount(array('limit' => 2, 'start' => $oneMonth));


To something like this?



$monthAll = TravelItem::getAllMount(array('limit' => 3, 'start' => $oneMonth));
//(Changed the limit to 3, which should increase how many unique months appear after $oneMonth

RomanTaylor
01-16-2012, 09:19 PM
Yes, sir. And nothing changed.

I've also tried changing $oneMonth to a value just to see if it will work. But it didn't, all it did is display December no matter what value replaced (I've tried 1,3, and 5) $oneMonth.

RomanTaylor
01-17-2012, 10:52 PM
Any more suggestions? I am really excited to find a solution for this without rewriting everything from scratch which I'd rather not do since I am not familiar with this site database and general structure.

RomanTaylor
01-24-2012, 04:57 AM
Help anyone?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum