PHP counter increment in a while loop

前端 未结 5 1962
一生所求
一生所求 2021-01-29 08:33

Im having a problem incrementing a counter in one of my while loops basically i just want to alternate between two image links that were fetched in my database but my counter wo

5条回答
  •  余生分开走
    2021-01-29 09:15

    Initialize $i outside the loop.

    $i = 0;
    while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
          $img_link = $row['Image'];
          $img_link_alt = $row['Image_alt'];
    
           echo '
    '; $img = ( $i % 2 == 0 ) ? $img_link : $img_link_alt; echo $i; //'?' . date("h:i:sa").' echo ''; echo '

    Screenshot

    Updated Screenshot of the Botting session: ' . $row['script_name'] .' '; echo '
    '; $i++; }

提交回复
热议问题