You are here:  » Issue with first line of css not responding as the other lines


Issue with first line of css not responding as the other lines

Submitted by I-CRE8 on Sun, 2020-09-27 17:24 in

Hi,

I have been using your script for many years to do a simple upload for customers to upload a csv with model numbers and insert new prices etc.

However I have had a request for a slightly new function which is to print out a list of model numbers that are not present in the database that are in the CSV, so I set up some sample code like so:

{code saved}

However whatever is contained in the first row always returns zero rows regardless of whether it is in the database or not.

Example data returned:
Array
(
[FIELD1] => SGV68U53UC
[FIELD2] => 899
)
SGV68U53UC
SELECT pkID FROM ModelPrice WHERE SKU = 'SGV68U53UC'
Resource id #26
0 rows returned
Array
(
[FIELD1] => BCDJ142SS
[FIELD2] => 249
)
BCDJ142SS
SELECT pkID FROM ModelPrice WHERE SKU = 'BCDJ142SS'
Resource id #27
1 rows returned
Array
(
[FIELD1] => GPE12FGKWW
[FIELD2] => 699
)
GPE12FGKWW
SELECT pkID FROM ModelPrice WHERE SKU = 'GPE12FGKWW'
Resource id #28
1 rows returned
Array
(
[FIELD1] => LMXS28596D
[FIELD2] => 1847
)
LMXS28596D
SELECT pkID FROM ModelPrice WHERE SKU = 'LMXS28596D'
Resource id #29
1 rows returned

what could be the issue here ?

Many Thanks

Submitted by support on Mon, 2020-09-28 07:15

Hi,

I can't see anything obvious that would cause that, what I would suggest though would be to make your database link resource global within myRecordHandler() and use that in the call to mysql_query; e.g.

  function myRecordHandler($record)
  {
    global $link;
    $sql = "SELECT * FROM table WHERE ...";
    $result = mysql_query($sql,$link);
  }
  $link = mysql_connect("localhost","username","password");
  mysql_select_db("database",$link);
  MagicParser_parse(...);

Hope this helps!
Cheers,
David
--
MagicParser.com

Submitted by I-CRE8 on Mon, 2020-09-28 09:27

David,

thanks but unfortunately that didn't work, I have even tried pushing the values into a global array and looping through that and it still doesn't work. There is something about the format of the 1st result that causes the query to fail

Dave Buchholz

Submitted by support on Mon, 2020-09-28 09:56

Hi Dave,

I wonder if your source file contains UTF-8 BOM (Byte Order Mark) characters at the beginning of the file... These are intended for use in human readable documents and shouldn't really be in datafeeds but if the file was created in a text editor or word processor they have may have been added by default.

As there are various byte sequences depending on the application / actual encoding, what I would suggest is that if your SKU (as $record["FIELD1"]) is guaranteed to be only numbers and upper case letters would be to use preg_replace to remove anything else that may be present in the value, such as the BOM, for example:

  $sku = preg_replace("/[^A-Z0-9]/","",$record["FIELD1"]);

Hope this helps!
Cheers,
David
--
MagicParser.com

Submitted by I-CRE8 on Mon, 2020-09-28 10:06

David,

that did the trick, thank you very much

Dave Buchholz