Answer the question
In order to leave comments, you need to log in
How to count all my elements in sql?
I have an online store and I need when I click on the basket to display all the goods, but I need it to display, for example, not Apple, Apple, Apple, but Apple 3 pcs here is the code
if message.text == 'Посмотреть продажи!':
if len(mas_user_id) > 0: можно не образать внимание
con = sqlite3.connect("telebot00.db") присоеденение
cur = con.cursor()
count_back = 0
order = 'Orders' это так таблица называеться
back_result = cur.execute(f"""SELECT * FROM {order}""").fetchall() просто чтение данных из таблицы
# Вывод результатов на экран
c = 0
for back_elem in back_result: проходим по данным
count_back = count_back + 1
back = back + str(count_back) + ') '
back = back + str(back_elem[1])
back = back + ' @'
back = back + str(back_elem[2])
back = back + ', '
back = back + str(back_elem[4])
back = back + ': '
back = back + ', '
back = back + str(back_elem[3])
countere = Counter(back_elem[3].split())
print(countere)
back = back + ', '
back = back + str(back_elem[3])
bot.send_message(message.from_user.id, back + '❗')
back = ''
else:
bot.send_message(message.from_user.id, 'Пока-что продаж нету ')
Answer the question
In order to leave comments, you need to log in
Alternatively, baskets can be stored in one table, for example Orders
, while storing the user id and the number of the product that was added, and it is desirable to add a primary key to delete items that were deleted by the user.
There will be something like:
+---+---------+-------------+-------+
| id | user_id | product_id | count |
+---+---------+-------------+-------+
SELECT count FROM Orders WHERE user_id = "user_id" AND product_id = "product_id ";
DELETE FROM Orders WHERE id = "id";
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question