S
S
Studentka19962020-12-06 01:08:49
Python
Studentka1996, 2020-12-06 01:08:49

How to output one number using a for loop?

For those who do not understand that I am implementing this in a bot, read the tags carefully :)

I'm tired of inventing .. maybe stupid, but I want to implement it like this:

if 'Далее' in text:
        for i in range(2, 6): #Создала список чисел (для rowid)
            #LIMIT 1 OFFSET 2 - получить 1 строку, начиная со 2 записи
            #Определим общее кол-во записей выбранной категории
            connect_cursor.execute(f'''SELECT Ф.Имя, GROUP_CONCAT(Объем ||' '|| Цена_руб ||' '|| Код), Описание, Состав, Ф.В_наличие, Расширение, Путь_к_файлу
            FROM Товар Т JOIN Фото Ф ON Т.Товар = Ф.Имя JOIN Атрибут_товара А ON Т.Код_атрибута = А.Код GROUP BY Ф.Имя LIMIT 1 OFFSET {i+1}''') 
            show_infoTovars()


How to make it so that only when you click "Next" the next product is displayed

There is a list [2, 3, 4, 5]
Next -> 2
Next-> 3
Next -> 4
Next -> 5

Please help. I will be glad to new ideas for solving this issue.

PS This option won't work:
for i in range(2, 6): #Создала список чисел (для rowid)
        if text == 'Далее':
            #LIMIT 1 OFFSET 2 - получить 1 строку, начиная со 2 записи
            #Определим общее кол-во записей выбранной категории
            connect_cursor.execute(f'''SELECT Ф.Имя, GROUP_CONCAT(Объем ||' '|| Цена_руб ||' '|| Код), Описание, Состав, Ф.В_наличие, Расширение, Путь_к_файлу
            FROM Товар Т JOIN Фото Ф ON Т.Товар = Ф.Имя JOIN Атрибут_товара А ON Т.Код_атрибута = А.Код GROUP BY Ф.Имя LIMIT 1 OFFSET {i+1}''') 
            show_infoTovars()

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
o5a, 2020-12-06
@Studentka1996

This "Next" is apparently taken from the bot's keyboard? Those. this is the result of the callback. You can pass the id of the next element "Next_3" to the callback_data and use it when parsing the callback (either as a list index, or rowid, or similar, depending on your logic).
Another option is to store a dictionary with menu states for each user (chat.id). Accordingly, it will be possible to look at the current state in the dictionary and after each "Next" update the next one. Let's put it this way: Still, this way of pulling records, through sequential limit 1 offset X polls, does not guarantee consistent results without explicit sorting (order by).
menu_info[message.chat.id]['next_id']

L
Leonid, 2020-12-06
@LeoMay

Create a list, iterate over it by index

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question