douyan8413 2012-05-12 02:00
浏览 31
已采纳

通过PHP为回显数据分配一个数字

This code selects the first five rows based on the criteria expressed in the select statement then it fetches the data from the columns specified by number then it echos the returned data to the page.

if( $connect === false )
{
  echo "Could not connect.
";
  die( print_r( sqlsrv_errors(), true));
}

/* Select Statement */
$select = "SELECT TOP(5)name, lv FROM Character WHERE lv > 0 AND name NOT LIKE '%@%' AND name NOT LIKE '%[GM]%'
AND name NOT LIKE '%[GA]%' AND name NOT LIKE '%[DEV]%' ORDER BY lv DESC ";

/* Execute the query. */
$query = sqlsrv_query( $connect, $select);

if ( $query )
{
} 
else 
{
  echo "Error in statement execution.
";
  die( print_r( sqlsrv_errors(), true));
}

/* Iterate through the result set printing a row of data upon each
iteration.*/
while( $row = sqlsrv_fetch_array( $query, SQLSRV_FETCH_NUMERIC))
{
 echo "<b>Name</b>: &nbsp;".$row[0]." <br/>";
 echo "<b>Level</b>: &nbsp;".$row[1]."<br/>";
 echo "<br/>";

}

/* Free statement and connection resources. */
sqlsrv_free_stmt( $query);
sqlsrv_close( $connect);
?>

What I need it to do is the echoed data, must have a number, for example: higher level will be 1st and so on. This already orders the data by level, but I can't manage to echo a number for each name. My thought was to making them to appear inside an ol and each user name will be inside a li so by default you can style list to display numbers in order. Then I can't manage to think how to do that. Could you give me some hints? Thanks!

  • 写回答

1条回答 默认 最新

  • dongzuoyue6556 2012-05-12 02:04
    关注

    I think this is what you're looking for. It will print a number before each name.

    $counter = 1;
    while( $row = sqlsrv_fetch_array( $query, SQLSRV_FETCH_NUMERIC))
    {
     echo $counter.". <b>Name</b>: &nbsp;".$row[0]." <br/>";
     echo "<b>Level</b>: &nbsp;".$row[1]."<br/>";
     echo "<br/>";
     $counter++;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。