strago Posted August 12, 2010 Share Posted August 12, 2010 $insertCount=0; foreach($results[1] as $curName) { if($insert){$insertCount++;} echo <<< END $curName<BR> END; } Right now the results would show up as... Bill Fred Jessica James John How do you make them show up like... 1 Bill 2 Fred 3 Jessica 4 James 5 John Link to comment https://forums.phpfreaks.com/topic/210510-number-each-entry/ Share on other sites More sharing options...
DavidAM Posted August 12, 2010 Share Posted August 12, 2010 Keeping to your code example: $insertCount=0; foreach($results[1] as $curName) { if($insert){$insertCount++;} echo <<< END $insertCount $curName<BR> END; } Although, I would probably do this: $insertCount=0; foreach($results[1] as $curName) { if($insert){$insertCount++;} printf('%d %s<BR>', $insertCount, $curName); } Link to comment https://forums.phpfreaks.com/topic/210510-number-each-entry/#findComment-1098367 Share on other sites More sharing options...
strago Posted August 12, 2010 Author Share Posted August 12, 2010 Yah, I had tried the $insertCount $curName<BR> but it only spit it out as... 1 Bill 1 Fred 1 Jessica 1 James 1 John Then printf('%d %s<BR>', $insertCount, $curName); did the same thing. For some reason it's not actually counting. Link to comment https://forums.phpfreaks.com/topic/210510-number-each-entry/#findComment-1098374 Share on other sites More sharing options...
JasonLewis Posted August 12, 2010 Share Posted August 12, 2010 What's with the $insert variable? Is that set, and is it true. Where are you pulling this variable from. Try this: $insertCount=0; foreach($results[1] as $curName) { $insertCount++; echo <<< END $insertCount $curName<BR> END; } Link to comment https://forums.phpfreaks.com/topic/210510-number-each-entry/#findComment-1098418 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.