0

下面我有值,下面我有一个 while 循环,其中有多个按 $top_list_friends['workouts'] 排序的值,最高的数字在顶部。

如何将以下值合并到一个列表中?

 echo "<div class='user'>";
 echo "<span class='number'>" . $my_rank . "</span>";
 echo "<span class='name'>" . $personal['name'] . "</span>";
 echo "<span class='workouts'>" . $personal['workouts'] . "</span>";
 echo "</div>";

 $i = 0;                                                                                                                  
 while ($top_list_friends = mysql_fetch_array($query_top_list_friends)) {
 $i++;

 echo "<div class='user'>";
 echo "<span class='number'>" . $i . "</span>";
 echo "<span class='name'>" . $top_list_friends['name'] . "</span>";
 echo "<span class='workouts'>" . $top_list_friends['workouts'] . "</span>";
 echo "</div>";             
 } 
4

2 回答 2

1

不太了解问题,但我会这样做:

    $name = $personal['name'];
    $workouts = $personal['workouts'];
    $html = <<<html
        <div class='user'>
        <span class='number'>$my_rank</span>
        <span class='name'>$name</span>
        <span class='workouts'>$workouts</span>
        </div>
html;

     $i=0;                                                                                                               
     while ($top_list_friends = mysql_fetch_array($query_top_list_friends)) {
     $i++;
     $topName = top_list_friends['name'];
     $topW = $top_list_friends['workouts']
     $html += <<<html
         <div class='user'>
         <span class='number'>$i</span>
         <span class='name'>$topName</span>
         <span class='workouts'>$topW</span>
         </div>
html;
    } 
    echo $html;
于 2013-10-13T17:41:51.053 回答
0

开头:

$inserted=0;

进入循环:

if(!$inserted && $personal['workouts']> $top_list_friends['workouts'])}
     $inserted=0;
    //first div echoes

}

在最后

if(!$inserted){

  //the same echos

}
于 2013-10-13T17:42:10.263 回答