Jump to content

Uniqe records to mysql


mAngel

Recommended Posts

Hi, have got a problem with adding uniqe records to m my table here is structure:

CREATE TABLE IF NOT EXISTS `ranges` (

  `stroid` int(11) NOT NULL AUTO_INCREMENT,

  `name` varchar(255) NOT NULL,

  `ip` varchar(15) NOT NULL,

  `code` varchar(2) NOT NULL,

  `ripe` varchar(255) NOT NULL,

  PRIMARY KEY (`stroid`),

  UNIQUE KEY `ripe` (`ripe`)

) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

 

in ripe I want to keep ip ranges like "127.0.0.1 - 127.0.0.2" so I set it to uniqe but:

1)When I've run mysql to check if it's allready inside db how to figure if it is or not.

2)how to optimize the code

3)first I use DISTRICT to get no double lines from mysql but I think no good to add double to mysql

 

so rest of my code

 $dane = file("dane.txt");
         $ilosc_rang = count($dane);

	$test = file_exists("dane.txt"); 									
   		if (!$test) 														
  		  {
   			 echo "no file on server" .$dane; 					

   		  }
   	    else
              {
	for ($i=0; $i <$ilosc_rang; $i++)                                 
	{

	//echo $dane[$i]."<br />";

	}

        if ($ilosc_rang == 0)                                             
        {
         	echo("file is blank");
        }

	for ($i=0 ; $i<$ilosc_rang; $i++)
	{
	$linia[$i] = explode (" - ",$dane[$i]);         					

	}
	echo ("how many ranges:".$ilosc_rang)."<br />";  

         }

for ($i=0; $i<$ilosc_rang; $i++)
{
		$ip=$linia[$i][0];

		$idcheck = $DB->fetch_row("SELECT stroid FROM ranges WHERE ip='" . $ip . "'");

		if(!empty($idcheck['stroid']) && empty($stroid))
		{	
			echo '<p>This range is allready in database</p>';
			exit;
		}

	else{


$netname="just test";
$countrinf-"cc";
$ripe="127.0.0.1";
$DB->query($sql = "INSERT INTO `test`.`ranges` (`stroid`, `name`, `ip`, `code`, `ripe`) VALUES (NULL, '$netname', '$ip', '$countryinfo', '$ripe');");

	}

	}



}

 

if anyone have got solution... :)

Thx in advance

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.