A
A
Anastasia2021-07-26 05:25:48
PHP
Anastasia, 2021-07-26 05:25:48

How can the design be optimized?

Hello. I’ll make a reservation right away: I don’t need code, but help in building the right application logic.
Essence such:
I store at myself the data in a DB. Through the bot, I check the same data on a third-party service. If they change, I write them to my database. Regardless of the changes, for each request, I send myself the result of the request in the cart. There is a lot of data, so in my cart they are displayed as a slider (forward and backward). The button properties store the record ID in the database, the current position and the action (forward or backward).

Procedure:
I make a request to a foreign server.
As a result, I will receive either an array of data or null
If there is an array of data, then
1. I convert the array into a string
2. I inform that there is data
3. I compare the data from a DB. If they differ, I enter them in the database, and if they match, I put a mark in a separate field and immediately get the number of the last entry in the
database in the database

Otherwise, if null, then
- I inform you that there is no data.
- I compare the data from a DB. In case of their difference, I enter it in the database, and in case of a match, I put a mark in a separate field and immediately get the number of the last record in the database

spoiler
60fe1d2a5254a980624403.png

I don't like the repetition of an action: I compare data from the database. If they differ, I enter them in the database, and if they match, I put a mark in a separate field and immediately get the number of the last entry in the database . I need to add to the database even if there is no data, because then it is used to get the history of the change.

In fact, until I have entered the data into the database, I cannot display an alert in the cart, because I need to know the record ID. But I can't know the post ID while I convert the array to a string.

How can you optimize the code other than putting this action into a function?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question