href中的增量数

时间:2014-07-22 04:39:22

标签: php mysql twitter-bootstrap

我是PHP的新手并且在这方面苦苦挣扎了一段时间,所以任何帮助者都会受到赞赏。

使用bootstrap我有一个无序的列表,我想用来显示mysql的记录。

我可以通过几种不同的方式显示记录没有问题,但似乎我无法使用我选择的引导程序布局。主要问题是尝试将递增数字附加到以下内容:

<?php 

            include 'dbconnect.php';

            $info =  mysql_query("SELECT firstname, lastname, postalcode, date, phone, timeframe, city, available FROM (SELECT * FROM `custdata` ORDER BY id DESC LIMIT 0 , 3) t ORDER BY id ASC") or die(mysql_error());

            $count=1;

            while ($info = mysql_fetch_array($newusers)) {

            echo"
                <div class='panel panel-default'>
                <div class='panel-heading'>
                <h4 class='panel-title'>
                <a data-toggle='collapse' data-parent='#accordion_leads' href='#collapse".$count."'>";

                echo $info['firstname']." ".$info['lastname']."<div style= float:right>". $info['postalcode'].""</div>";

                </a></h4></div>";

                echo '<div id="collapse'.$count.'" class="panel-collapse collapse">';

                 echo "<div class="panel-body">";

                      echo 
                      "<ul class=list-group style=font-size:13px>
                      <li class=list-group-item> <strong>Location:</strong>", $info['city'],
                      "</li><li class=list-group-item><strong>Date:</strong>", $info['date'], 
                      "</li><li class=list-group-item><strong>Phone:</strong>", $info['phone'], 
                      "</li><li class=list-group-item> <strong>Timeframe:</strong>", $info['timeframe'], 
                      "</li><li class=list-group-item> <strong>Availability:</strong>", $info['available'],"</li>
                      </ul></div></div>"; 

                     $count ++; } ?>

2 个答案:

答案 0 :(得分:0)

试试这个

<?php
     $count=0;
     while ($info = mysql_fetch_array($newusers)) 
     { ?>
       <div class="panel panel-default">
          <div class="panel-heading">
              <h4 class="panel-title">
                 <a data-toggle="collapse" data-parent="#accordion_leads" href="#collapse<?php echo $count; ?>">
                   <?php echo  $info['firstname'].", ".$info['lastname']; ?>
                    <div style='float:right'><?php echo ", ".$info['postalcode'] ?></div>
                 </a>
              </h4>
          </div>
       <div id="collapse<?php echo $count; ?>" class="panel-collapse collapse">
     <?php $count ++; } ?>

答案 1 :(得分:0)

试试这个,只需复制我的代码并替换你的代码即可完成

<?php 

        $count=1;

        while ($info = mysql_fetch_array($newusers)) {

        echo"
          <div class='panel panel-default'>
            <div class='panel-heading'>
              <h4 class='panel-title'>
                <a data-toggle='collapse' data-parent='#accordion_leads' href='#collapse".$count."'>";

                echo $info['firstname']." ".$info['lastname']."<div style= float:right>". $info['postalcode'].""</div>";

                </a></h4></div>";

            echo '<div id="collapse'.$count.'" class="panel-collapse collapse">';

$count ++;
}
?>