array_slice() - sometimes has errors when total records is not even amount

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all,

NEWBIE: Here's the issue - I am trying to split and find query on a page into 2 columns using = array_slice().......

If the get found set count is an EVEN amount - then all is ok - but if not then I get an error and the last record on the bottom right like.....

Fatal error: Call to a member function getField() on a non-object in /home/test.php on line xxx

I think it has to do with LENGTH param...

- if I make length be $part1 -0 then I get error on bottom right if NOT even total
- if I make length be $part1 -1 then I get NO error on bottom right if NOT even total - BUT I DO NOT GET FULL RESULT (MISSING A RECORD)...


Q: HOW CAN I SET THIS UP SO NO ERRORS WHEN RESULT OF found set count is *NOT* an EVEN amount ?





<?php
$allrows = $mytest_result->getFoundSetCount();
$part1 = round($mytest_result->getFoundSetCount() / 2);
?>




<br />
all <?php
echo $allrows; ?><br />
part1 <?php
echo $part1; ?><br />
<br />




<?php 


// ERROR unless use -1 - check if correct ??? now ok i guess

$firstNameSet = array_slice($mytest_result->getRecords(), 0, $part1 -0 ); // ERROR unless use -1 - check if correct ??? now ok i guess

$secondNameSet = array_slice($mytest_result->getRecords(), $part1 -0 ); // ERROR unless use -1 - check if correct ??? now ok i guess

?>



<?php 

foreach ($firstNameSet as $key => $nameA) {
$nameB = $secondNameSet[$key];
 ?>
  
  
   <?php echo $nameA->getField('myfield'); ?>
   
   <?php 
}  ?>





<?php 

foreach ($firstNameSet as $key => $nameA) {
$nameB = $secondNameSet[$key];
 ?>
  
  
   <?php echo $nameA->getField('myfield'); ?>
   
   divs here etc......
   
   <?php echo $nameB->getField('myfield'); ?>
   
  
   
   <?php 
}  ?>

--
Thanks,
Dave - DealTek
dealtek@xxxxxxxxx
[db-15]


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux