我如何在一个while循环内的<li>标记内创建一个自动递增的ID?

时间:2018-12-08 00:37:19

标签: php mysql sql loops mysqli

这是我的代码:

function buscarCategs() {

    global $con;

    $buscar_categ = "SELECT * FROM categorias";

    $run_categ = mysqli_query($con, $buscar_categ);


    while ($row_categs = mysqli_fetch_array($run_categ)) {

        $categ_id = $row_categs['categ_id'];
        $categ_titulo = $row_categs['categ_titulo'];

        echo "<li class='celulaCategoriasMenu' onmouseover='javascript:showMenu(); ' onmouseout='javascript:hideMenu();'>$categ_titulo</li><div id='linkMenuAbre' class='linkMenuAbre'>Teste</div>";
    }
}

那么,如何在“ while”内创建一个循环,以生成自动递增的ID并发布到“ echo”上?

例如:echo "<li id='idselector_1'></li>"echo "<li id='idselector_2'></li>"echo "<li id='idselector_3'></li>"

我尝试用foreach创建一个循环,但是没有用。

1 个答案:

答案 0 :(得分:1)

添加一个using System; using System.Text; using System.Threading.Tasks; using org.apache.zookeeper; // NuGet: ZooKeeperNetEx namespace Example { // Watcher will notify us of events we get from ZooKeeper class MyWatcher : Watcher { public override async Task process(WatchedEvent @event) { Console.WriteLine($"Process event: {@event}"); } } class Program { async static Task Main() { // Create a new ZK client. var zookeeper = new ZooKeeper("<zookeeper-url>", sessionTimeout: 3000, new MyWatcher()); // Use it to request a config setting. var connectionData = await zookeeper.getDataAsync("/common-settings/connectionString"); // Convert the received data from bytes to string. var connectionString = Encoding.UTF8.GetString(connectionData.Data); Console.WriteLine($"Got connectionString '{connectionString}'."); // Got connectionString '1.1.1.1:123' Console.Read(); } } } 变量,您可以在每个循环中递增该变量。

$id