To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
While testing I have $phone and $surname as values that I know are in the database, but it still executes the INSERT query, and deosnt stop with the die(). In addition mysql_error() doesnt give me anything.
$query = "SELECT a.PART_ID, b.DESCRIPTION, count(a.PART_ID) as number FROM CUST_ORDER_LINE as a, PART as b WHERE a.PART_ID = b.ID AND a.PART_ID NOT LIKE '%FIN%' AND a.PART_ID NOT LIKE 'CI%' AND a.PART_ID NOT LIKE '%D&M%' AND a.PART_ID NOT LIKE 'PRECHA%' AND a.PART_ID NOT LIKE 'works van' AND a.PART_ID NOT Like '[0-9][0-9]SHT[0-9][0-9][0-9][0-9]' AND a.PART_ID NOT Like '[0-9][0-9]TIM[0-9][0-9][0-9][0-9]' GROUP BY a.PART_ID, b.DESCRIPTION ORDER BY number desc";
As you may see, in each array (line) i am getting a double results...one with integer indexes and another with assoc indexes. I would like only assoc. Is this usual or am missing soething in my code??
WHOA! Hold on! None of these ways are how you avoid duplicates, because they're all vulnerable to race conditions. I.e. someone can insert the same thing between when you select for dupes and insert.
You avoid duplicates with unique indexes. Since a unique index on a large text field is large and unwieldy, it's an easy cheat to do something like create a separate field, and put and md5 of the text field in there, and make the unique index on that field.
create table posts (id int autoincrement, textarea text, checksum text);
$text = "this is a test message";
insert into posts (textarea, checksum) values ('$text',md5sum($text));
Get the idea? If they try to insert the same thing twice, the unique index on the md5checksum should catch it every time, no race condition.
__________________
PostgreSQL version 8.5 is now in alpha!
Race conditions have nothing to do with the color of your skin...
T1 us transaction 1, T2 is transaction 2.
T1: select count(*) from db where message = 'abc'; <-- abc not in database, count==0
T2: select count(*) from db where message = 'abc'; <-- abc not in database, count==0
milliseconds pass...
T1: insert into db values ('abc');
T2: insert into db values ('abc');
__________________
PostgreSQL version 8.5 is now in alpha!