gibson98 Posted October 26, 2017 Share Posted October 26, 2017 Hi, Can anyone help please. I am getting unwanted duplicates displayed in my script and the more records I add the more duplicates it has. There are no duplicate records in the MYSQLi database and am a little confused to why this is happening and how to go about solving it can anyone help please? <?php //Include Database Connection File from Includes/Config include 'includes/config/db.inc.php'; //Select Database and Tables $sql = "SELECT * FROM dow_list_01, dow_settings, dow_page_content ORDER BY dow_list_sort_order"; $result = $conn->query($sql); ?> <!doctype html> <?php //Load Data from Database if($result->num_rows > 0) { while($row = $result->fetch_assoc()){ ?> <html> <head> <meta charset="utf-8"> <title><?php echo $row['dow_website_title']; ?> - <?php echo $row['dow_title']; ?></title> <meta name="robot" content="<?php echo $row['dow_meta_robot']; ?>"> <meta name="description" content="<?php echo $row['dow_meta_description']; ?>"> <meta name="keywords" content="<?php echo $row['dow_meta_keywords']; ?>"> <link href="includes/css/frontendmenutop.css" rel="stylesheet" type="text/css"> <script type="text/javascript" src="includes/picker/js/jquery.colorpicker.js"></script> <script type="text/javascript" src="includes/picker/js/jquery.classygradient.js"></script> <style> body { <?php echo $row['dow_background']; ?> } .page_banner { height: <?php echo $row['dow_banner_height']; ?>; } .page_menu { background:<?php echo $row['dow_nav_bar_color']; ?> } .page_menu a { color: <?php echo $row['dow_nav_font_color']; ?>; font-family: <?php echo $row['dow_nav_font']; ?> } .page_menu li { background:<?php echo $row['dow_nav_bar_color']; ?> } .page_menu li:hover { background:<?php echo $row['dow_nav_hover_color']; ?> } .page_container { <?php echo $row['dow_body']; ?> } .list_item{ <?php echo $row['dow_list_hide']; ?> } </style> </head> <body> <div class="page_container"> <div class="page_banner"><img src="images/upload/webdesign/banner/<?php echo $row['dow_banner']; ?>"></div> <div style="clear: both"></div> <!doctype html> <?php //Load Data from Database if($result->num_rows > 0) { while($list = $result->fetch_assoc()){ ?> <div class="list_item"> <div style="float:left; width:260px"><a href="list_content01.php?id=<?php echo $list['dow_list_id']; ?>"><img src="images/upload/list01/<?php echo $list['dow_list_image_folder']; ?>/000.jpg" style="width:260px; height:152px"></a></div> <div style="float:left; width:660px; height:152px; max-height: 152px; overflow: hidden; padding-left:10px"><?php echo $list['dow_list_description']; ?></div> </div><div style="clear: both"></div> <?php } } else { ?> <div>No Page Content Found</div> <?php } ?> </div> <?php } } else { ?> <div>No Page Content Found</div> <?php } ?> </body> </html> Thanks alot for any help in advance! Kind Regards Joe Quote Link to comment Share on other sites More sharing options...
Barand Posted October 26, 2017 Share Posted October 26, 2017 You appear to have a while() loop starting on line 13 which will output the page (including the html header content) several times. Inside this loop you have another while loop to output the records. Quote Link to comment Share on other sites More sharing options...
Phi11W Posted October 30, 2017 Share Posted October 30, 2017 Your SQL is wrong: SELECT * FROM dow_list_01, dow_settings, dow_page_content ORDER BY dow_list_sort_order Your select statement mentions three tables but gives your database engine no clue how to "join" them together sensibly. Faced with such a request, your database will dutifully (and stupidly) join each and every record in the first table to each and every record in the second table (and then to each and every record in the third table!). It's known as a Cartesian (or Cross) Join and, in all but a tiny handful of cases, it is a [Performance-Crucifying], Data-Duplicating mistake. Also relevant, but far less important in this instance; avoid using "select * from ...". Databases are inherently a shared resource and if, in a few years time, somebody [else] were to add a hundred really, really big text fields to this table, you'd suddenly find your application running really, really slowly, as all that data - that your page doesn't actually [know or] care about - comes out of the database and chugs its way across the network. Regards, Phill W. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.