Jump to content

Mysqli getting unwanted duplicates displayed :(


gibson98

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.