dpgui8229808 2015-12-06 17:12
浏览 68
已采纳

在PHP应用于数据检索之后,网站在循环中重复

well I probably ran into a problem this morning and trying to figure out where I'm going wrong. The page was working fine without the PHP but as soon as I stuffed this page with statements from PHP (For displaying data in my website) I observed that my website was repeating with the number of records. Say, 5 records are to be displayed in the website then the website repeats 5 times. I'm using MySQL, PHPmyAdmin and HTML. Any help would be greatly appreciated and I hope I'm not missing out on something very usual. Before looking at the code I would recommend you to just go through the PHP part because before adding PHP, the site was functioning very normally! Here's all you will need: My HTML code for the particular page:

<?php
error_reporting(E_ALL ^ E_DEPRECATED);
session_start();
if (!(isset($_SESSION['state']) && $_SESSION['state'] != '')) {
header ("Location: ../login.php");
}
else
{ 
include_once ('E:/Softwares/wamp/www/connection.php');
    $username = $_SESSION['username'];
    $result = mysql_query("SELECT *from `movie_schedule`");

if(mysql_num_rows($result))
{while($row = mysql_fetch_array($result, MYSQL_BOTH))
{

?>
<!DOCTYPE html>
<html>
    <head>
        <title>The CineShed Cinemas</title>
        <link href="css/style.css" rel="stylesheet" type="text/css" media="all" />
        <link href="css/bootstrap1.css" rel="stylesheet" type="text/css" media="all">
        <!-- web-font -->
        <link href='http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,300,700,800,400,600' rel='stylesheet' type='text/css'>
        <link href='http://fonts.googleapis.com/css?family=Poiret+One' rel='stylesheet' type='text/css'>
        <link href='http://fonts.googleapis.com/css?family=Merriweather:400,700italic,400italic,300,900,700,900italic,300italic' rel='stylesheet' type='text/css'>
        <!-- web-font -->
        <!-- js -->
        <script src="js/jquery.min.js"></script>
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <script type="application/x-javascript"> addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); } </script>
        <!-- js -->
        <!-- start-smoth-scrolling -->
        <script type="text/javascript" src="js/move-top.js"></script>
        <script type="text/javascript" src="js/easing.js"></script>
        <script type="text/javascript">
            jQuery(document).ready(function($) {
                $(".scroll").click(function(event){     
                    event.preventDefault();
                    $('html,body').animate({scrollTop:$(this.hash).offset().top},1000);
                });
            });
        </script>
    <!-- start-smoth-scrolling -->
    </head>
    <body>
        <!-- header -->
        <div id="home" class="header">
            <!-- container -->
            <div class="container">
                <div class="header-logo">
                    <h1><a href="#">The CineShed<span> Cinemas<br>-------------------------------<br>You've logged in as ADMIN</span></a></h1>
                </div>
                <div class="top-nav">
                    <p><a class="Signup play-icon popup-with-zoom-anim" href="#small-dialog3"></a><span> <a href="logout.php">Log Out</a></P>
                </div>
                <div class="clearfix"> </div>
                <!-- banner Slider starts Here -->
                <script src="js/responsiveslides.min.js"></script>
                 <script>
                    // You can also use "$(window).load(function() {"
                    $(function () {
                      // Slideshow 4
                      $("#slider4").responsiveSlides({
                        auto: true,
                        pager: true,
                        nav: false,
                        speed: 500,
                        namespace: "callbacks",
                        before: function () {
                          $('.events').append("<li>before event fired.</li>");
                        },
                        after: function () {
                          $('.events').append("<li>after event fired.</li>");
                        }
                      });

                    });
                  </script>
                <!--//End-slider-script -->
                <div  id="top" class="callbacks_container">
                    <ul class="rslides" id="slider4">
                        <li>
                            <div class="header-info">
                            <p>BY<span> ZARYAB</span><span class="sub-text"> Ali</span></p>
                            <p>Experience the</p>
                            <p> third dimension!</p>
                            <div class="red">DOLBY DIGITAL 3-D</div>
                            <!--
                            <div class="button"><a href="#">View Here</a></div>
                            -->

                            </div>
                        </li>
                        <li>
                            <div class="header-info">
                                <p>BY<span> ZARYAB</span><span class="sub-text"> Ali</span></p>
                                <p>Premium Seating?</p>
                                <p> We've got this covered!</p>
                                <div class="red">TITAN XC</div>

                            </div>
                        </li>
                        <li>
                            <div class="header-info">
                                <p>BY<span> ZARYAB</span><span class="sub-text"> Ali</span></p>
                                <p>Enjoy the awesomeness</p>
                                <p> of explosive sound!</p>
                                <div class="red">WITH 7.1 AUDIO CHANNELS!</div>
                            </div>
                        </li>
                        <li>
                            <div class="header-info">
                                <p>BY<span> ZARYAB</span><span class="sub-text"> Ali</span></p>
                                <p>Activities to keep</p>
                                <p> your wee ones busy!</p>
                                <div class="red">KID'S CORNER</div>

                            </div>
                        </li>
                        <li>
                            <div class="header-info">
                                <p>BY<span> ZARYAB</span><span class="sub-text"> Ali</span></p>
                                <p>A mouth-watering</p>
                                <p> menu awaits you!</p>
                                <div class="red">@ Arizona Grill</div>

                            </div>
                        </li>
                    </ul>
                    <div class="clearfix"> </div>
                    <!-- banner Slider Ends Here --> 
                </div>
            </div>
            <!-- container -->
        </div>
        <!-- header -->
        <!-- sticky -->
        <div class="sticky">
            <!-- container -->
            <div class="container">
                <div class="top-header">
                    <div class="fixed-header">
                    <div class="sticky-logo">
                        <h1><a class="scroll" href="#home">The CineShed <span>Cinemas</a> </span></h1>
                    </div>  
                    <div class="sticky-nav">
                        <ul>
                            <li><a class="scroll active" href="#banner">View Trailers</a></li>   
                            <li><a class="scroll" href="#manage">Manage Show Times</a></li>
                            <li><a class="scroll" href="#offpur">View Purchases</a></li>
                        </ul>
                    </div>
                    <div class="clearfix"> </div>
                    </div>
                </div>
            </div>
            <!-- container -->  
        </div>
        <!-- sticky -->
        <!-- script-for sticky-nav -->
        <script>
        $(document).ready(function() {
             var navoffeset=$(".top-header").offset().top;
             $(window).scroll(function(){
                var scrollpos=$(window).scrollTop(); 
                if(scrollpos >=navoffeset){
                    $(".top-header").addClass("fixed");
                }else{
                    $(".top-header").removeClass("fixed");
                }
             });

        });
        </script>
        <!-- /script-for sticky-nav -->
        <!-- banner -->
        <div id="banner" class="banner">
            <a class="play-icon popup-with-zoom-anim" href="#small-dialog"><span> </span></a>
            <!-- pop-up-box -->
                    <script type="text/javascript" src="js/modernizr.custom.min.js"></script>    
                    <link href="css/popuo-box.css" rel="stylesheet" type="text/css" media="all" />
                    <script src="js/jquery.magnific-popup.js" type="text/javascript"></script>
                    <!--//pop-up-box-->
                <div id="small-dialog" class="mfp-hide">
                    <iframe src="https://www.ytpak.com/?component=video&task=embed&id=R-XsppzuH-k&branding=no" scrolling="NO" frameborder="0" width="100%" height="315" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
                    <iframe src="https://www.ytpak.com/?component=video&task=embed&id=K-H35Mpj4uk&branding=no" scrolling="NO" frameborder="0" width="100%" height="315" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
                    <iframe src="https://www.ytpak.com/?component=video&task=embed&id=K-H35Mpj4uk&branding=no" scrolling="NO" frameborder="0" width="100%" height="315" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
                    </div>  
                <div id="small-dialog3" class="mfp-hide">
                    <div class="login">
                        <h3>Login</h3>
                        <p>Enter your account details to login</p>
                        <input type="text" maxlength="20" value="EMAIL" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'EMAIL';}">          
                        <input type="text" maxlength="10" value="PASSWORD" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'PASSWORD';}">                            
                        <input type="submit"  value="Submit"/>
                    </div>
                </div>
                <div id="small-dialog2" class="mfp-hide">
                    <div class="signup">
                        <h3>Register</h3>
                        <h4>Please Enter Your Details</h4>
                        <input type="text" value="First Name" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'First Name';}" />
                        <input type="text" value="Second Name" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Second Name';}" />
                        <input type="text" class="email" value="Email" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Email';}"  />
                        <input type="text" class="password" value="Password" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Password';}"/>
                        <input type="text" class="email" value="Confirm password" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Confirm password';}"  />
                        <input type="submit" value="Submit"/>
                    </div>
                </div>  
                 <script>
                        $(document).ready(function() {
                        $('.popup-with-zoom-anim').magnificPopup({
                            type: 'inline',
                            fixedContentPos: false,
                            fixedBgPos: true,
                            overflowY: 'auto',
                            closeBtnInside: true,
                            preloader: false,
                            midClick: true,
                            removalDelay: 300,
                            mainClass: 'my-mfp-zoom-in'
                        });

                        });
                </script>   
        </div>
        <!-- banner -->

            <!-- container -->
            <div id="manage" class="container">
                <h3><br>Manage Show Times<br></h3>
                <div class="col-md-7">
                    <div class="col-md-6">
                        <form method="post" action="savemovie.php">
                            <input type="text" class="text" value="Movie ID" name="field1" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Movie ID';}">
                            <input type="text" class="text" value="Movie Date" name="field2" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Movie Date';}">
                            <input type="text" class="text" value="Show Time" name="field3" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Show Time';}">
                            <input type="text" class="text" value="Movie Cost" name="field4" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Movie Cost';}">



                            <input type="text" class="text" value="Movie Name" name="field5" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Movie Name';}">
                            <input type="text" class="text" value="Tickets Availability" name="field6" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Tickets Availability';}">


                    <div class="clearfix"> </div>
                    <div class="submit-button">


                            <input type="submit" value="ADD MOVIE">
                        </form>
                    </div>
                </div>

                <div class="clearfix"> </div>
            </div>
            </div>
            <!-- container -->
            <?php
                                  $result1 = mysql_query("SELECT *from `movie_schedule`");

if(mysql_num_rows($result1))
{while($row2 = mysql_fetch_array($result1, MYSQL_BOTH))
{
    ?>
        <!-- content-events -->
        <div id="event" class="content-event">
            <!-- container -->
            <div class="container">
                <h3>Show Times</h3>
                <div class="event-grids">
                    <div class="col-md-3 event-grid">
                        <div class="pic"> </div>
                        <ul>
                            <li class="hedding"><?php print($row2['Movie_ID']); ?> <?php print($row2['Movie_Name']); ?></li>
                            <li class="date"><?php print($row2['Movie_Date']); ?></li>
                        </ul>
                        <div class="clearfix"> </div>
                    </div>
                    <div class="col-md-4 event-grid small-text">
                        <p><br><?php print($row2['Show_Time']); ?></p>
                    </div>
                    <div class="col-md-2 event-grid large-text">
                        <p class="text"><?php print($row2['Movie_Cost']); ?></p>
                    </div>
                    <div class="col-md-3 event-grid text-button">
                        <ul>
                            <li class="num"><?php print($row2['Movie_ID']); ?></li>
                            <li class="button yellow"><a href="#">Remove</a></li>
                            </ul>
                            <?php
            }}
            ?>
                    </div>

            </div>
            <!-- container -->
        </div>
        <!-- contact-events -->

<!-- content-events -->
        <div id="offpur" class="content-event">
            <!-- container -->
            <div class="container">
                <h3>View Offline Purchases</h3>
                <div class="event-grids">
                    <div class="col-md-3 event-grid">
                        <div> </div>
                        <ul>
                            <li class="hedding">Offline Purchase ID</li>
                            <li class="date">(Serial Number)</li>
                        </ul>
                        <div class="clearfix"> </div>
                    </div>
                    <div class="col-md-4 event-grid small-text">
                        <p><br>Movie ID</p>
                    </div>
                    <div class="col-md-2 event-grid large-text">
                        <p class="text">Amount</p>
                    </div>
                    <div class="col-md-3 event-grid text-button">
                        <ul>
                            <li class="num">Quantity Of Tickets</li>

                        </ul>
                    </div>
                    <div class="clearfix"> </div>
                </div>
                <div class="event-grids">
                    <div class="col-md-3 event-grid">
                        <div> </div>
                        <ul>
                            <li class="hedding">111</li>
                            <li class="date"></li>
                        </ul>
                        <div class="clearfix"> </div>
                    </div>
                    <div class="col-md-4 event-grid small-text">
                        <p>01</p>
                    </div>
                    <div class="col-md-2 event-grid large-text">
                        <p class="text">2100 PKR</p>
                    </div>
                    <div class="col-md-3 event-grid text-button">
                        <ul>
                            <li class="num">3</li>

                        </ul>
                    </div>
                    <div class="clearfix"> </div>
                </div>
                <div class="event-grids">
                    <div class="col-md-3 event-grid">
                        <div> </div>
                        <ul>
                            <li class="hedding">112</li>
                            <li class="date"></li>
                        </ul>
                        <div class="clearfix"> </div>
                    </div>
                    <div class="col-md-4 event-grid small-text">
                        <p><br>03</p>
                    </div>
                    <div class="col-md-2 event-grid large-text">
                        <p class="text">1400 PKR</p>
                    </div>
                    <div class="col-md-3 event-grid text-button">
                        <ul>
                            <li class="num">2</li>

                        </ul>
                    </div>
                    <div class="clearfix"> </div>
                </div>
                <div class="event-grids">
                    <div class="col-md-3 event-grid">
                        <div> </div>
                        <ul>
                            <li class="hedding">115</li>
                            <li class="date"></li>
                        </ul>
                        <div class="clearfix"> </div>
                    </div>
                    <div class="col-md-4 event-grid small-text">
                        <p><br>02</p>
                    </div>
                    <div class="col-md-2 event-grid large-text">
                        <p class="text">3500 PKR</p>
                    </div>
                    <div class="col-md-3 event-grid text-button">
                        <ul>
                            <li class="num">5</li>

                        </ul>
                    </div>
                    <div class="clearfix"> </div>
                </div>
                <div class="event-grids">
                    <div class="col-md-3 event-grid">
                        <div> </div>
                        <ul>
                            <li class="hedding">124</li>
                            <li class="date"></li>
                        </ul>
                        <div class="clearfix"> </div>
                    </div>
                    <div class="col-md-4 event-grid small-text">
                        <p><br>02</p>
                    </div>
                    <div class="col-md-2 event-grid large-text">
                        <p class="text">2800 PKR</p>
                    </div>
                    <div class="col-md-3 event-grid text-button">
                        <ul>
                            <li class="num">4</li>

                        </ul>
                    </div>
                    <div class="clearfix"> </div>
                </div>
            </div>
            <!-- container -->
        </div>
        <!-- contact-events -->

        <!-- portfolio -->
        <div class="portfolio">
            <!-- container -->
            <div class="container">
                <h3>Gallery</h3>
                <div class="gallery-images">
                    <div class="gallery-image">
                        <img src="images/3.jpg" alt="" />
                        <div>
                            <span> </span>
                        </div>
                    </div>
                    <div class="gallery-image">
                        <img src="images/4.jpg" alt="" />
                        <div>
                            <span> </span>
                        </div>
                    </div>
                    <div class="gallery-image right">
                        <img src="images/5.jpg" alt="" />
                        <div>
                            <span> </span>
                        </div>
                    </div>
                    <div class="gallery-image">
                        <img src="images/7.jpg" alt="" />
                        <div>
                            <span> </span>
                        </div>
                    </div>
                    <div class="gallery-image">
                        <img src="images/6.jpg" alt="" />
                        <div>
                            <span> </span>
                        </div>
                    </div>
                    <div class="gallery-image right">
                        <img src="images/8.jpg" alt="" />
                        <div>
                            <span> </span>
                        </div>
                    </div>
                    <div class="clearfix"> </div>
                    <div class="gallery-text">

                    </div>
                </div>
            </div>
            <!-- container -->
        </div>
        <!-- portfolio -->
<!-- contact -->
        <div id="contact" class="contact">
            <!-- container -->
            <div class="container">
                <h3>Contact Us</h3>
                <div class="col-md-7">
                    <div class="col-md-6">
                        <form>
                            <input type="text" class="text" value="Name" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Name';}">
                            <input type="text" class="text" value="Email" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Email';}">
                        </form>
                    </div>
                    <div class="col-md-6">
                        <form>
                            <textarea value="Message:" onfocus="if(this.value == 'Message') this.value='';" onblur="if(this.value == '') this.value='Message';">Message</textarea>  
                        </form>
                    </div>
                    <div class="clearfix"> </div>
                    <div class="submit-button">
                        <form>
                            <input type="submit" value="SEND">
                        </form>
                    </div>
                </div>
                <div class="col-md-5">
                    <ul>
                        <li><a href="#" class="facebook"> </a></li>
                        <li><a href="#" class="twitter"> </a></li>
                        <li><a href="#" class="rect"> </a></li>
                    </ul>
                </div>
                <div class="clearfix"> </div>
            </div>
            <!-- container -->
        </div>
        <!-- contact -->
        <div class="border-bottom"> </div>
        <!-- footer -->
        <div class="footer">
            <div class="copyright">
                <p>
                    Designed By : Zaryab Ali (07410)
                </p>
            </div>
        </div>
        <!-- footer -->
        <script type="text/javascript">
                                    $(document).ready(function() {
                                        /*
                                        var defaults = {
                                            containerID: 'toTop', // fading element id
                                            containerHoverID: 'toTopHover', // fading element hover id
                                            scrollSpeed: 1200,
                                            easingType: 'linear' 
                                        };
                                        */

                                        $().UItoTop({ easingType: 'easeOutQuart' });

                                    });
                                </script>
                                    <a href="#" id="toTop" style="display: block;"> <span id="toTopHover" style="opacity: 1;"> </span></a>
    <!-- content-Get-in-touch -->
    <?php
}}}
?>
    </body>
</html>
  • 写回答

1条回答 默认 最新

  • 普通网友 2015-12-06 17:15
    关注

    You are creating the HEAD and BODY of you page in the loop that returns results from your database.This loop should be further in your page, where you are displaying the actual results, and should show only those results.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程