doulingzhuang3079 2013-06-30 02:05
浏览 8

PHP递增?

I have some PHP code here:

$a = 1;

echo "<div>$a</div>
<div class='alert alert-info' style='border-radius: 20px'>
<div style='padding: 10px; span5'>
<span class='label label-info' font-size='30px'><em>Tournament | Year | Round | Question # | Category</em></span><span style='margin-left: 500px; text-align: right'>ID: $id</span></div>
<b>$tournament |</b> <b>$year |</b> <b>$round |</b> <b>$num |</b> <b>$category</b>
<p><em>Question:</em> $question</p>
<div class='row'><div class='alert alert-info span7'><em><strong>ANSWER:</strong></em> $answer </div><div class='alert alert-info span2' align='right'>
<a href='#errorReportmodel' class='btn btn-inverse' data-toggle='modal'>Report an Error</a></div></div></div><hr>

";

I want a number ($a) to increment each time it is displayed (it is the results from a MySQL database search). Such as 1, 2, 3, 4, etc.

  • 写回答

2条回答 默认 最新

  • dougan1330 2013-06-30 02:20
    关注

    You don't really have PHP code there. You have HTML which is being echoed out by PHP. I say this not to be pedantic, but to help you understand why this isn't the code you need to edit (or at least, not the whole of it).

    It sounds like what you are looking for is a for loop. I'm guessing you already have one in somewhere above the code you pasted, but if not, you'll need to add it in. The type of code you are ultimately looking for is:

    echo "<table><tr><th>Table Headers</th><th>Go Here</th></tr>";
    $rowcount = 1;
    foreach ($tablerows as $row) {
        echo "<tr><td>".$rowcount."</td><td>Other row data></td><td>go here</td></tr>";
        $rowcount++;
    }
    echo "</table>";
    

    This will, for each row that you output, also output the current value of $rowcount which, each time through the loop, gets incremented by one.

    评论

报告相同问题?

悬赏问题

  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线