php - Numbered results list and maintain position number if times are equal -


i have results table iterate on , echo out.

$c = 1; foreach ($results $result) {     $r .= '<tr>'     . '<th scope="row">' . ($time === $result['time']? $c - 1 : $c)  . '</th>'     . '<td>' . $result['name'] . '</td>'     . '<td>' . $result['time'] . ' </td>'     . '<td>' . $result['points'] . ' </td>'     . '</tr>';      $time = $result['time'];     $c++; } 

i compare current time previous result time , display count same if match. e.g.
1. tom 0.33
2. ben 0.34
2. carl 0.34
4. des 0.35
5. dave 0.36

but if des had got 0.34? display count 3 , should stay on 2.

any ideas how solve without getting complex?

$c = 1; $lastc = $c; foreach ($results $result) {      if ($time === $result['time']) {         $place = $lastc;     } else {         $place = $c;         $lastc = $c;     }      $r .= '<tr>'     . '<th scope="row">' . $place  . '</th>'     . '<td>' . $result['name'] . '</td>'     . '<td>' . $result['time'] . ' </td>'     . '<td>' . $result['points'] . ' </td>'     . '</tr>';      $time = $result['time'];     $c++; } 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -