Answer the question
In order to leave comments, you need to log in
How do I add a sub category so that the python_sqlite button is added?
I have a category that I can then add a product to.
I want to create a category, then add a subcategory to it, and a product is already in the subcategory
All this creates inline
keyboards
class Catalog:
def __init__(self, name):
self.name = name
class Product:
def __init__(self, user_id):
self.user_id = user_id
self.product = None
self.section = None
self.price = None
self.amount = None
self.amount_MAX = None
self.code = None
class AddProduct:
def __init__(self, section):
self.section = section
self.product = None
self.price = None
self.info = None
class DownloadProduct:
def __init__(self, name_section):
self.name_section = name_section
self.name_product = None
class GiveBalance:
def __init__(self, login):
self.login = login
self.balance = None
self.code = None
class Admin_sending_messages:
def __init__(self, user_id):
self.user_id = user_id
self.text = None
# Menu catalog
def menu_catalog():
conn = sqlite3.connect("base_ts.sqlite")
cursor = conn.cursor()
cursor.execute('SELECT * FROM catalog')
row = cursor.fetchall()
menu = types.InlineKeyboardMarkup(row_width=1)
for i in row:
menu.add(types.InlineKeyboardButton(text=f'{i[0]}', callback_data=f'{i[1]}'))
menu.add(types.InlineKeyboardButton(text='Назад', callback_data='exit_to_menu'))
cursor.close()
conn.close()
return menu
# Menu section
def menu_section(name_section):
conn = sqlite3.connect("base_ts.sqlite")
cursor = conn.cursor()
cursor.execute(f"SELECT * FROM '{name_section}' ")
row = cursor.fetchall()
menu = types.InlineKeyboardMarkup(row_width=1)
for i in row:
menu.add(types.InlineKeyboardButton(text=f'{i[0]}', callback_data=f'{i[2]}'))
menu.add(types.InlineKeyboardButton(text='Назад', callback_data='exit_to_menu'))
cursor.close()
conn.close()
return menu
# Menu product
def menu_product(product, dict):
conn = sqlite3.connect("base_ts.sqlite")
cursor = conn.cursor()
row = cursor.execute(f'SELECT * FROM section WHERE code = "{product}"').fetchone()
section = row[1]
info = row[3]
amount = len(cursor.execute(f'SELECT * FROM "{product}"').fetchall())
cursor.execute(f'SELECT * FROM "{section}" WHERE code = "{product}"')
row = cursor.fetchone()
dict.section = section
dict.product = product
dict.amount_MAX = amount
dict.price = row[1]
text = settings.text_purchase.format(
name=row[0],
info=info,
price=row[1],
amount=amount
)
return text, dict
# Admin menu - add_to_section_to_catalog
def add_section_to_catalog(name_section):
# Connection
conn = sqlite3.connect("base_ts.sqlite")
cursor = conn.cursor()
code = random.randint(11111, 99999)
# Add
cursor.execute(f"INSERT INTO catalog VALUES ('{name_section}', '{code}')")
conn.commit()
# Create table section
conn.execute(f"CREATE TABLE '{code}' (list text, price text, code text)")
# Close connection
cursor.close()
conn.close()
# Admin menu - del_section_to_catalog
def del_section_to_catalog(name_section):
# Connection
conn = sqlite3.connect("base_ts.sqlite")
cursor = conn.cursor()
# Del
cursor.execute(f"DELETE FROM catalog WHERE code = '{name_section}'")
conn.commit()
cursor.execute(f"DROP TABLE '{name_section}'")
row = cursor.execute(f'SELECT * FROM section WHERE section = "{name_section}"').fetchall()
for i in range(len(row)):
cursor.execute(f'DROP TABLE "{row[i][2]}"')
cursor.execute(f'DELETE FROM section WHERE code = "{row[i][2]}"')
conn.commit()
# Close connection
cursor.close()
conn.close()
# Admin menu - add_product_to_section
def add_product_to_section(name_product, price, name_section, info):
# Connection
conn = sqlite3.connect("base_ts.sqlite")
cursor = conn.cursor()
code = random.randint(11111, 99999)
cursor.execute(f"INSERT INTO '{name_section}' VALUES ('{name_product}', '{price}', '{code}')")
conn.commit()
cursor.execute(f"INSERT INTO 'section' VALUES ('{name_product}', '{name_section}', '{code}', '{info}')")
conn.commit()
# Create table product
cursor.execute(f"CREATE TABLE '{code}' (list text, code text)")
# Close connection
cursor.close()
conn.close()
# Admin menu - del_product_to_section
def del_product_to_section(name_product, section):
# Connection
conn = sqlite3.connect("base_ts.sqlite")
cursor = conn.cursor()
# del
product = cursor.execute(f'SELECT * FROM "{section}" WHERE list = "{name_product}"').fetchone()
cursor.execute(f"DELETE FROM '{section}' WHERE list = '{name_product}'")
conn.commit()
cursor.execute(f"DROP TABLE '{product[2]}'")
# Close connection
cursor.close()
conn.close()
Answer the question
In order to leave comments, you need to log in
@another_dream so your request is not formed correctly
$result = $mysqli->query("SELECT * FROM `entry` WHERE `descr` LIKE '%{$query}%' OR `content` LIKE '%{$query}%' OR `title` LIKE '%{$query}%'");
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question