Hi,
I'm having problem with some scripts im working on. I made a script that takes advertisements from a text file (a mssql dump from an old classifieds website) and "translates" them to fit into the PHP classifieds system (mysql). I have a few functions, one that adds the users to the database, and one that adds the adverts themselfs. This is what I'm having problems with, I have a loop going that extracts each seperate ad from the text file, and updates the mysql datbase, so I have a for loop that updats the db for every ad it extracts. Now, there are about 30 000 exntries in the text file, but only about 26 000 ads are entered into the database 🙁. I edited the script abit, to see how many ad's it extracts (not yet updated into the db), and it returned about 30 000 so the problem isnt in the part of the script that extracts the ad's from the text file.
Next I made another script that does the loop again, and if the entry doesnt exist in the database (after running the rist script) it adds the advert, thus eliminating the ad's that didnt get added the first time. It doesnt work 🙁 I either get errors about mysql_num_rows not being a valid resource, or nothing at all, but no ad's are updated. here is the code for the update (2nd) script:
connect_db($host, $user, $pass, $dbase);
$splits = explode('|', $readfile);
$num_splits = count($splits);
for ($i=0; $i<$num_splits; $i++)
{
$field = explode('","', $splits[$i]);
$num_fields= count($field);
$field[0]= str_replace('"', "", $field[0]);
$title = $field[8];
$description = $field[9];
$views = $field[13];
$email = $field[4];
$rubriek = $field[2];
$datetime = $field[10];
$sql = "select * from ad where ad_username='$email' and sitetitle='$title'";
if(!$result = mysql_query($sql))
{
global $rubriek_convert;
$rubriek_n = $rubriek_convert[$rubriek]; //convert old category id to new one
$date = convert_date($datetime); //convert format of date
$sql = "INSERT into ad (siteid,del,sitetitle,sitedescription,sitedate,sitecatid,sitehits,sitevotes,sitevoters,sitevoters_ip,picture,img_stored,datestamp,ad_username,valid,expire_days,sold,notify,is_special,sitescore) values ('',NULL,'$title','$description','$date','$rubriek_n','$views',NULL,NULL,NULL,NULL,NULL,'$datetime','$email',NULL,'90',NULL,NULL,NULL,'0.00')";
$result = mysql_query($sql);
}