Webmaster Forum


Go Back   Webmaster Forum > Web Development > Web Design Lobby > Coding Forum
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Coding Forum Problems with your code? Let's hear about it.

Directory Submission Service   I Sell Pagerank   V7N Directory

Reply
 
LinkBack Thread Tools Display Modes
Old 09-14-2006, 06:21 AM   #1 (permalink)
Inactive
 
Join Date: 09-14-06
Posts: 4
iTrader: 0 / 0%
Latest Blog:
None

Nodda4me is liked by many
Dupe Detection and Sorting

Hello forum! I'm wondering how to detect duplicate entry and remove it before adding it to a database. I also would like to know how to sort a list by IP and by name.

Thanks,
Nodda4me

PHP Code:
$song=$_GET['song'];
$ver=$_GET['ver'];
$date=date("Y-m-d G:i:s");
$date2=date("D M j");
$time=date("g:i:s A");
$ip=$_SERVER['REMOTE_ADDR'];
mysql_connect($host,$username,$password);
@
mysql_select_db($database) or die( "Unable to select database");
$query "INSERT INTO `LF` VALUES ('','$date','$time','$ip','$song', '$date2', '$ver')";
mysql_query($query);

mysql_close(); 
Nodda4me is offline  
Add Post to del.icio.us
Reply With Quote
Sponsored Links
SEO Hosting by HostGator  Advertise Here  Buy Blog Links
Old 09-14-2006, 07:47 AM   #2 (permalink)
Inactive
 
littleFella's Avatar
 
Join Date: 06-20-04
Location: Ontario
Posts: 3,359
iTrader: 0 / 0%
Latest Blog:
None

littleFella is a splendid one to beholdlittleFella is a splendid one to beholdlittleFella is a splendid one to beholdlittleFella is a splendid one to beholdlittleFella is a splendid one to beholdlittleFella is a splendid one to beholdlittleFella is a splendid one to beholdlittleFella is a splendid one to beholdlittleFella is a splendid one to beholdlittleFella is a splendid one to beholdlittleFella is a splendid one to behold
Quote:
Originally Posted by Nodda4me
Hello forum! I'm wondering how to detect duplicate entry and remove it before adding it to a database. I also would like to know how to sort a list by IP and by name.

Thanks,
Nodda4me

PHP Code:
$song=$_GET['song'];
$ver=$_GET['ver'];
$date=date("Y-m-d G:i:s");
$date2=date("D M j");
$time=date("g:i:s A");
$ip=$_SERVER['REMOTE_ADDR'];
mysql_connect($host,$username,$password);
@
mysql_select_db($database) or die( "Unable to select database");
$query "INSERT INTO `LF` VALUES ('','$date','$time','$ip','$song', '$date2', '$ver')";
mysql_query($query);

mysql_close(); 
This is one of the ways you may use to weed out the dupes.

PHP Code:
 $result mysql_query("SELECT * FROM ..... WHERE Field1=someValue and Field2 = someValue");
$count mysql_num_rows($result); 
if ( 
$count == 
{
  
$query "INSERT INTO `LF` VALUES ('','$date','$time','$ip','$song', '$date2', '$ver')";
  
mysql_query($query); 

else 
{
  echo 
"Dupes aint allowed";

sorting is done by appendind this to the end of the select statement:

ORDER BY Field1,Field2... [asc/desc]



The only issue may be the IP sorting since the way computers sort numbers is not the way we always want them to be sorted. For instance, given these three values 1,5,12 the sort result may be the following:

1
12
5

In order to remedy the problem you will need to left pad the elements to be sorted with a 0 as illustrated below:

01
05
12

Of course it would be silly to show IP in the format 069.123.001.003 so the left padding needs to be done in the background. There are a few wways to do that; you may try one of the two below:

1. create a variable (or an array of variables) in which each IP address would have an equivalent with the left padded zeros. This will however require you to use one of the commonly used sorting algos such as QuickSort, BubbleSort etc. Not difficult but some find it easier to do as much as possible in SQL rather than the programming language code. SQL uses B-Trees and/or other advanced data structures too, so things are much faster.

2. The second method (one I would recommned) will involve the following:

- add a field to the table, say IP_SORT
- every time a record is added, prefix IP fields entered by user with Zeros and add thus prefixed value to the IP_SORT field as a new value. For instance, if someone posts 24.150.67.6 change it to 024.150.067.006. Notice that IP field already containing 3 digits gets no 0 prefix. Other fields get:

Number of Prefix Zeros = 3 - Number of Digits on the IP Field

3. When you need to display the records sorted by IP do the following query:

PHP Code:
 Select IP_ADDRESSSONGNAMEDATE from SomeTable where something=blah_blah
Order by IP_SORT 
[,someSecondarySortField
Hope this helps.

Last edited by littleFella : 09-14-2006 at 07:50 AM.
littleFella is offline  
Add Post to del.icio.us
Reply With Quote
Old 09-14-2006, 07:59 AM   #3 (permalink)
Inactive
 
Join Date: 09-14-06
Posts: 4
iTrader: 0 / 0%
Latest Blog:
None

Nodda4me is liked by many
Ok, let's scratch the IP sorting for now.

PHP Code:
$result mysql_query("SELECT * FROM ..... WHERE Field1=someValue and Field2 = someValue"); 
I have a program that adds an error by using INET

Code:
wb.Navigate "http://domain.net/XXXXX/lf/?song=(" & vArtist & ") - (" & vSong & ")&ver=" & GetVer(FullVer)
Example of this would be:

http://domain.net/XXXXX/lf/?song=(Godsmack) - (Bad Religion)&ver=2.7


I want it to check if $song is already in the database; there are no text fields in any of the php code.

Thanks,
Nodda4me
Nodda4me is offline  
Add Post to del.icio.us
Reply With Quote
Old 09-14-2006, 03:41 PM   #4 (permalink)
Inactive
 
littleFella's Avatar
 
Join Date: 06-20-04
Location: Ontario
Posts: 3,359
iTrader: 0 / 0%
Latest Blog:
None

littleFella is a splendid one to beholdlittleFella is a splendid one to beholdlittleFella is a splendid one to beholdlittleFella is a splendid one to beholdlittleFella is a splendid one to beholdlittleFella is a splendid one to beholdlittleFella is a splendid one to beholdlittleFella is a splendid one to beholdlittleFella is a splendid one to beholdlittleFella is a splendid one to beholdlittleFella is a splendid one to behold
I have to admit I'm lost.
littleFella is offline  
Add Post to del.icio.us
Reply With Quote
Old 09-14-2006, 03:47 PM   #5 (permalink)
Inactive
 
Join Date: 09-14-06
Posts: 4
iTrader: 0 / 0%
Latest Blog:
None

Nodda4me is liked by many
Quote:
Originally Posted by littleFella
I have to admit I'm lost.
Ok, I have a program that submits errors:
http://domain.com/asf.php?error=error7

I want the php script to include a duplicate detection, if "error7" is already in the MySQL database, then don't add it.

I hope this clears things up.

Thanks,
Nodda4me
Nodda4me is offline  
Add Post to del.icio.us
Reply With Quote
Old 09-15-2006, 10:51 PM   #6 (permalink)
Inactive
 
littleFella's Avatar
 
Join Date: 06-20-04
Location: Ontario
Posts: 3,359
iTrader: 0 / 0%
Latest Blog:
None

littleFella is a splendid one to beholdlittleFella is a splendid one to beholdlittleFella is a splendid one to beholdlittleFella is a splendid one to beholdlittleFella is a splendid one to beholdlittleFella is a splendid one to beholdlittleFella is a splendid one to beholdlittleFella is a splendid one to beholdlittleFella is a splendid one to beholdlittleFella is a splendid one to beholdlittleFella is a splendid one to behold
You posted no details about your database structure. I suggested some algos.
Sorry if this may sound unfriendly, but... as gently as I can; do you know what you are talking about? Did you ever do any PHP/SQL coding other than "select * ..."?
littleFella is offline  
Add Post to del.icio.us
Reply With Quote
Old 09-19-2006, 05:51 AM   #7 (permalink)
Contributing Member
 
helloworld's Avatar
 
Join Date: 06-29-06
Posts: 72
iTrader: 0 / 0%
Latest Blog:
None

helloworld is liked by somebodyhelloworld is liked by somebodyhelloworld is liked by somebodyhelloworld is liked by somebodyhelloworld is liked by somebody
littleFella already gave you the answer.

My suggestion is similiar
Code:
////query giberish here if ( $count == 0 ) { ///insert it into the database giberish here } else { die(); ///or use exit; .... }
helloworld is offline  
Add Post to del.icio.us
Reply With Quote
Go Back   Webmaster Forum > Web Development > Web Design Lobby > Coding Forum

Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
sorting data alphabetically gnznroses Coding Forum 3 03-12-2007 12:31 PM
Sorting items by a given rating. bit of a problem... gnznroses Coding Forum 19 08-10-2006 09:05 PM
ASP File Sorting SN3 Web Design Lobby 9 09-12-2005 11:58 AM
Sandboxed, GoogleJacked or Penalised for dupe content!?! pitpony Google Forum 1 02-28-2005 12:35 PM
Did Excite's translation cause a dupe penalty for Bluefind? walkman Google Forum 1 12-18-2004 11:08 PM


Sponsor Links
Get exposure! Get exposure! Find Scripts Web Hosting Directory Get exposure! SEO Blog


All times are GMT -7. The time now is 09:42 PM.
© Copyright 2008 V7 Inc