【问题标题】:single line break In while loopwhile循环中的单行换行符
【发布时间】:2018-11-15 22:51:57
【问题描述】:

我想在我的 while 循环中有一个 <br>。 如果我添加<br>,我会为单个项目添加<br>,我想要的是在<img><button> 之间只显示<br>。所以不是每个按钮都分开。有人可以帮我吗?

<?php
if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) 
    {
?>

<img src="<?php echo $result_question['img'];?>">

<input type="button" id="<?php echo $row["answer_id"];?>" next_question_id="<?php echo $row["next_question_id"];?>" value="<?php echo $row["answer_text"];?>" onclick=myFunction2((this.id));>

<?php   
    }
} 
$conn->close();
?>

【问题讨论】:

  • 对不起。我无法理解您的要求。您能否详细说明,以便我可以提供帮助?
  • 在打印前检查$row["answer_text"]$row["answer_id"]是否符合您想要的文本或ID
    ;

标签: php html loops while-loop


【解决方案1】:

这是你的意思吗?

<?php
if ($result->num_rows > 0) {
    $c = 0;
    // output data of each row
    while($row = $result->fetch_assoc()) 
    {
?>

<img src="<?php echo $result_question['img'];?>">
<?php if ($c == 0){ ?><br/><?php } ?> 

<input type="button" id="<?php echo $row["answer_id"];?>" next_question_id="<?php echo $row["next_question_id"];?>" value="<?php echo $row["answer_text"];?>" onclick=myFunction2((this.id));>

<?php  
    $c++; 
    }
} 
$conn->close();
?>

【讨论】:

    猜你喜欢
    • 2013-02-17
    • 2014-04-18
    • 1970-01-01
    • 2010-11-20
    • 1970-01-01
    • 2017-02-11
    • 1970-01-01
    • 2017-08-21
    • 1970-01-01
    相关资源
    最近更新 更多