Jump to content

Statement that sets special MySQL entries for duplicate content


Elven6

Recommended Posts

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  :D.

 

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.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.