Import csv is importing values as 0

41 views
Skip to first unread message

Harold Smith

unread,
Dec 4, 2023, 2:19:45 PM12/4/23
to Joomla! General Development
Most of the fields are being imported correctly, but the `created_by`, `created`, `modified_by`, `modified`, `checked_out`, and `checked_out_time` fields are all being imported as zeros. Can anyone provide me with a hint on how to fix this issue or how to use a variable to fill a field?

$stmt = $conn->prepare("REPLACE `$prefix" . "autos` (`id`, `auto_id`, `title`, `alias`, `category_id`, `featured`, `features_text`, `description`, `image`, `gallery`, `auto_status`, `rent_period`, `price`, `currency_format`, `currency_position`, `currency`, `dealer_id`, `country`, `city`, `state`, `address`, `map`, `zip`, `vehicle_condition`, `doors`, `mileage`, `drive`, `engine`, `transmission`, `body`, `fuel_type`, `vehicle_year`, `features`, `video_text`, `video`, `interior_text`, `interior`, `published`, `language`, `access`, `ordering`, `created_by`, `created`, `modified_by`, `modified`, `checked_out`, `checked_out_time`)
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
$stmt->execute([$row[0], $row[1], $row[2], $row[3], $row[4], $row[5], $row[6], $row[7], $row[8], $row[9], $row[10], $row[11], $row[12], $row[13], $row[14], $row[15], $row[16], $row[17], $row[18], $row[19], $row[20], $row[21], $row[22], $row[23], $row[24], $row[25], $row[26], $row[27], $row[28], $row[29], $row[30], $row[31], $row[32], $row[33], $row[34], $row[35], $row[36], $row[37], $row[38], $row[39], $row[40], $row[41], $row[42], $row[43], $row[44], $row[45], $row[46]]);

Harold Smith

unread,
Dec 4, 2023, 2:41:26 PM12/4/23
to Joomla! General Development
Update:  Actually it is only created_by, created

seraphim

unread,
Dec 5, 2023, 7:20:42 AM12/5/23
to joomla-de...@googlegroups.com
Not sure if I understand your question well but you can use the null coalescing operator to give a default value when your field in the row is empty instead of 0 like this:

$created_by = $row[41] ?? 'anonymous';  if created_by is a string field in your table or $created_by = $row[42] ?? 999; if it is an integer field.
$created = $row[42] ?? '1970-01-01'; if it is a date field for example.

In your execute array you replace $row[41] and $row[42] with $created_by and $created of course.

Hope this helps a bit.
--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-gene...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/joomla-dev-general/af674166-b1c3-4df2-bddd-e10af8aa0016n%40googlegroups.com.


Harold Smith

unread,
Dec 5, 2023, 10:09:28 AM12/5/23
to Joomla! General Development
Seraphim,

Thank you for your suggestion, but unfortunately, it doesn't seem to be working.
After trying several unsuccessful methods out of desperation, I attempted the following, which surprisingly worked: $row[41] = $currentuser_id.
Reply all
Reply to author
Forward
0 new messages