For statement in a While
Posted: Thu May 27, 2010 3:24 pm
I have Smarty template engine being used on the site and I wrote this code to work with Smarty..
Smarty PHP
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
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
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);
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...
}