Re: Compare two arrays in mysql

From: Date: Thu, 21 Dec 2000 10:55:33 +0000
Subject: Re: Compare two arrays in mysql
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-31398@lists.php.net to get a copy of this message
what about storing UNIQUE keys as needed in the database, inserting (without prior select), catching errno, and displaying 'this data already exists' if needed? At 11:40 21.12. 2000, Admin wrote the following: -------------------------------------------------------------- >hi all, > >i have two arrays. The first one resulting from a selection of a form and the second one >resulting from a row in mysql. >Now, how can i compare these two arrays and if there are no doubles insert them into mysql? > >//The first array. This is where it sucks as it doesnt compare this array with the second one. >mysql_connect("$DBHost","$DBUser","$DBPass"); >mysql_select_db ("$DBName"); >$result = mysql_query ("SELECT THISDATA FROM THISDATA > WHERE THISDATA = '$THISDATA"); >($row = mysql_fetch_array($result)); >if ($result == $THISDATA >{ > print ("<b>Error:</b> THISDATA ALREADY EXISTS IN OUR > DATABASE<b>"); > print ("$THISDATA"); > print ("</b> Go back and enter a new THISDATA."); > print ("<p>"); > $verify = "bad"; >} >else >{ > >//This is the second array (resulting from a user selection)which will be inserted into mysql >ONLY if the data from this arrays doesnt already exist in another table. Which means that i have to >fetch just one row of a table and compare it with the one from the user. >mysql_connect("$DBHost","$DBUser","$DBPass"); >mysql("$DBName","INSERT INTO shoppers VALUES >('$UID','$date','tempID')"); >for($count = 0; $count < sizeof($MYARRAY); $count++) >{ >mysql("$DBName","INSERT INTO basket VALUES >('$UID','$MYARRAY[$count]','2','$date','$BasketItem')"); >Header("Location: viewBasket.php?UID=$UID"); >} >} > > >//Thanks in advance ------end of quote------ ____________________________________________________________ Cynic: A member of a group of ancient Greek philosophers who taught that virtue constitutes happiness and that self control is the essential part of virtue. cynic@mail.cz

« previous php.general (#31398) next »