Page 1 of 1

For statement in a While

Posted: Thu May 27, 2010 3:24 pm
by bla5e
I have Smarty template engine being used on the site and I wrote this code to work with Smarty..

Smarty PHP

Code: Select all

while ($rows = pg_fetch_assoc($sql)){
      $row[] = $rows;
 }
$smarty->assign('row',$row);

$max = 0;
for($i=0; $i<count($row); $i++){
  $row[$i]['previousrank'] = $row[$i-1]['position'];
  $row[$i]['nextrank'] = $row[$i+1]['position'];
  if(!isset($min) || (isset($min) && $row[$i]['position'] < $min)){
    $min = $row[$i]['position'];
  }
  if($row[$i]['position'] > $max){
    $max = $row[$i]['position'];
  }
}
$smarty->assign('min', $min);
$smarty->assign('max', $max);
works great with smarty, but I have an Ajax call to refresh which is a duplicate of the smarty php file, (except it doesnt use smarty, its just straight PHP)

how do I get that peice of code to work within a while statement?

Non-Smarty PHP

Code: Select all

while ($row = pg_fetch_assoc($sql)){
 //rows, and database data loaded...
 //the For statement posted above, needs to work inside this while...
}
please help I have a headache trying to figure this out! If i put the for statement inside the while, the page doesnt load.. no syntax errors just doesnt do anything

Re: For statement in a While

Posted: Fri May 28, 2010 1:50 pm
by bla5e
changed the while to a foreach worked.. :banghead: