Elven6 Posted July 26, 2010 Share Posted July 26, 2010 I am working on a piece of code that will allow my site to not show duplicate post content. I created a new database table entry called "dup" in the table which the CMS posts content to. If the post you are submitting is a duplicate it will randomly set the variable to 1 for all but one of the entries which it sets to 0. By doing this the duplicate entries would not appear on the front page but would still be in the database and would be accessible by either going to the systems category or game id if one is attached. So if the database has to create three entries for a single post it will randomly set two of them to 1 but the third to 0. With the CMS, multiple entires are added if the user selects multiple system platforms, if they choose Xbox 360 and PlayStation 3 for their platforms for instance the post would be entered twice for each platform, unfortunately, it also shows up twice on the front page. Here is a snippet of the code that is used for adding content to the database once it is submitted, it's the most recent but not the best of my experiments by any means . if ($_GET['view'] == "add2") { for($i = 0; $i < $_POST['s']; $i = $i+1) { if ($_POST["name_$i"]) { while (list(, $val) = each ($_POST["systems_$i"])) { if ($_POST["systems_$i"] > 0) { for($_POST["systems_$i"] > 0) { $dup = '1'; } } else { $dup = '0'; } $upd = "INSERT INTO ".$pre."content VALUES (null, '".addslashes($_POST["name_$i"])."', '".$_POST["cat_$i"]."', '".$_COOKIE[$pre."username"]."', '".time()."', '".$dup."'"; if ($ver == "yes") { $upd .= ", '1', '', '0', '".$_POST["lev$i"]."'"; } else { $upd .= ", '0', '', '0', '".$_POST["lev$i"]."'"; } I've been experimenting with various techniques regarding If and While statements but haven't been able to come up with anything. Just to sum things up, the code needs to check to see if more than one entry for a single post is being added to the database and if that is the case it will set dup to 1 for all but one of the entires. Link to comment https://forums.phpfreaks.com/topic/208948-statement-that-sets-special-mysql-entries-for-duplicate-content/ Share on other sites More sharing options...
Pikachu2000 Posted July 26, 2010 Share Posted July 26, 2010 Wouldn't it be infinitely easier to use SELECT DISTINCT to avoid displaying duplicates? Link to comment https://forums.phpfreaks.com/topic/208948-statement-that-sets-special-mysql-entries-for-duplicate-content/#findComment-1091493 Share on other sites More sharing options...
Elven6 Posted July 27, 2010 Author Share Posted July 27, 2010 Wouldn't it be infinitely easier to use SELECT DISTINCT to avoid displaying duplicates? How does that work? Link to comment https://forums.phpfreaks.com/topic/208948-statement-that-sets-special-mysql-entries-for-duplicate-content/#findComment-1091503 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.