-1

我正在尝试显示卡片,但是通过这种方式,所有三张卡片都显示相同的信息,而我希望每张卡片都显示数据库中的特定条目,例如第一个是第一个条目,第二个是第二个,第三个是第三个然后更改行并重新启动以显示 4、5、6 条目等。有人可以帮忙吗?

include_once('db/connection.php');
        $query="select * from news ORDER BY id DESC";
        $result=mysqli_query($conn,$query);
    
           ?>
    <?php
    
    while($rows=mysqli_fetch_array($result))
    {  
        $cc =$rows['category2'];
        ?>
        <div>
            <div class="container">
                <div class="cust_bloglistintro">
                
                    <div class="row">
                        <div class="col-md-6 col-lg-4 cust_blogteaser" style="padding-bottom: 20px;margin-bottom: 32px;height: 750px;">
                            <div class="card" data-aos="fade-up" style="height: 700px;"><img class="card-img-top w-100  d-block" src="images/<?php echo $rows['thumbnail'];?>">
                                <div class="card-body">
                                    <h4 class="card-title"><?php echo $rows['title']; ?></h4><span style="font-family: 'Open Sans', sans-serif;font-size: 12px;margin-bottom: 5px;"><?php echo $rows['3']; ?></span>
                                    <p class="card-text"><?php echo substr($rows['2'],0,400); ?></p><?php if($cc=="bigbites"){?><a class="card-link" href="bigbites.php?ii=<?php echo $rows['0']?>>" target="_top">Read more...</a><?php } else{?><a class="card-link" href="<?php echo $rows['7']; ?>" target="_top">Read more...</a><?php }?>
                                </div>
                                <div class="text-center" style="bottom: 10px;"><a href="extra.php?ii=<?php echo $rows['0']?>"><i class="fab fa-whatsapp-square" id="whatsapp"></i></a><a href="extra.php?ii=<?php echo $rows['0']?>"><i class="fab fa-facebook-square" id="facebook"></i></a><a href="extra.php?ii=<?php echo $rows['0']?>"><i class="fab fa-linkedin" id="linkedin"></i><a href="extra.php?ii=<?php echo $rows['0']?>"><i class="fas fa-share" id="share"></i></a></div>
                            </div>
                        </div>
    
                        <div class="col-md-6 col-lg-4 cust_blogteaser" style="padding-bottom: 20px;margin-bottom: 32px;height: 750px;">
                            <div class="card" data-aos="fade-up" style="height: 700px;"><img class="card-img-top w-100  d-block" src="images/<?php echo $rows['thumbnail'];?>">
                                <div class="card-body">
                                    <h4 class="card-title"><?php echo $rows['title']; ?></h4><span style="font-family: 'Open Sans', sans-serif;font-size: 12px;margin-bottom: 5px;"><?php echo $rows['3']; ?></span>
                                    <p class="card-text"><?php echo substr($rows['2'],0,400); ?></p><?php if($cc=="bigbites"){?><a class="card-link" href="bigbites.php?ii=<?php echo $rows['0']?>>" target="_top">Read more...</a><?php } else{?><a class="card-link" href="<?php echo $rows['7']; ?>" target="_top">Read more...</a><?php }?>
                                </div>
                                <div class="text-center" style="bottom: 10px;"><a href="extra.php?ii=<?php echo $rows['0']?>"><i class="fab fa-whatsapp-square" id="whatsapp"></i></a><a href="extra.php?ii=<?php echo $rows['0']?>"><i class="fab fa-facebook-square" id="facebook"></i></a><a href="extra.php?ii=<?php echo $rows['0']?>"><i class="fab fa-linkedin" id="linkedin"></i><a href="extra.php?ii=<?php echo $rows['0']?>"><i class="fas fa-share" id="share"></i></a></div>
                            </div>
                        </div>
    
                        <div class="col-md-6 col-lg-4 cust_blogteaser" style="padding-bottom: 20px;margin-bottom: 32px;height: 750px;">
                            <div class="card" data-aos="fade-up" style="height: 700px;"><img class="card-img-top w-100  d-block" src="images/<?php echo $rows['5'];?>">
                                <div class="card-body">
                                    <h4 class="card-title"><?php echo $rows['1']; ?></h4><span style="font-family: 'Open Sans', sans-serif;font-size: 12px;margin-bottom: 5px;"><?php echo $rows['3']; ?></span>
                                    <p class="card-text"><?php echo substr($rows['2'],0,400); ?></p><?php if($cc=="bigbites"){?><a class="card-link" href="bigbites.php?ii=<?php echo $rows['0']?>>" target="_top">Read more...</a><?php } else{?><a class="card-link" href="<?php echo $rows['7']; ?>" target="_top">Read more...</a><?php }?>
                                </div>
                                <div class="text-center" style="bottom: 10px;"><a href="extra.php?ii=<?php echo $rows['0']?>"><i class="fab fa-whatsapp-square" id="whatsapp"></i></a><a href="extra.php?ii=<?php echo $rows['0']?>"><i class="fab fa-facebook-square" id="facebook"></i></a><a href="extra.php?ii=<?php echo $rows['0']?>"><i class="fab fa-linkedin" id="linkedin"></i><a href="extra.php?ii=<?php echo $rows['0']?>"><i class="fas fa-share" id="share"></i></a></div>
                            </div>
                        </div>
                        
                    </div>
                </div>
            </div>
        </div>
        <?php
    }
    ?>
4

1 回答 1

-1

这样做的方法很多,但我最近使用过这种方法......

<?php
    
    $resultCount=0;
    if(mysqli_num_rows($result) >0)
    {
?>
            <div>
                <div class="container">
                    <div class="cust_bloglistintro">
                    
                        <div class="row">
<?php
        while($rows=mysqli_fetch_array($result))
        {  
            $cc =$rows['category2'];
            ?>

                         <div class="col-md-6 col-lg-4 cust_blogteaser" style="padding-bottom: 20px;margin-bottom: 32px;height: 750px;">
                            <div class="card" data-aos="fade-up" style="height: 700px;"><img class="card-img-top w-100  d-block" src="images/<?php echo $rows['thumbnail'];?>">
                                <div class="card-body">
                                    <h4 class="card-title"><?php echo $rows['title']; ?></h4><span style="font-family: 'Open Sans', sans-serif;font-size: 12px;margin-bottom: 5px;"><?php echo $rows['3']; ?></span>
                                    <p class="card-text"><?php echo substr($rows['2'],0,400); ?></p><?php if($cc=="bigbites"){?><a class="card-link" href="bigbites.php?ii=<?php echo $rows['0']?>>" target="_top">Read more...</a><?php } else{?><a class="card-link" href="<?php echo $rows['7']; ?>" target="_top">Read more...</a><?php }?>
                                </div>
                                <div class="text-center" style="bottom: 10px;"><a href="extra.php?ii=<?php echo $rows['0']?>"><i class="fab fa-whatsapp-square" id="whatsapp"></i></a><a href="extra.php?ii=<?php echo $rows['0']?>"><i class="fab fa-facebook-square" id="facebook"></i></a><a href="extra.php?ii=<?php echo $rows['0']?>"><i class="fab fa-linkedin" id="linkedin"></i><a href="extra.php?ii=<?php echo $rows['0']?>"><i class="fas fa-share" id="share"></i></a></div>
                            </div>
                        </div>
    
<?php
            $resultCount++;
            if ($resultCount % 3 == 0) // start new row
            {
?>
                        </div>
                
                    
                        <div class="row">
<?php
            }
        }
        
        if ($resultCount % 3 != 0) // if we didn't just end a row in the loop, end it now
        {
?>
                        </div>
<?php
        }

        // now close divs
?>      
                </div>
            </div>
        </div>
<?php
    } // end of if num_rows>0
?>
于 2021-02-12T09:28:30.163 回答