F
F
foxxx12342019-03-25 02:12:10
PHP
foxxx1234, 2019-03-25 02:12:10

How to make buttons in a row for a telegram bot?

I'm trying to make 3 buttons in a row for a telegram bot
There is a script
$countrys = DB::$the->query("SELECT * FROM `set_country` WHERE `active` = '1' ");
while ($country = $countrys->fetch()) {
$keyboard[] = ];
}
$bot->sendInlineKeyboard($id, $text, $keyboard);
Now displays 1 in a row. To display 3 buttons, you need to do
$keyboard[] = ,['text' => $country['name'], 'callback_data' => ' orderNumber ' . $country['provider_type']],['text' => $country['name'], 'callback_data' => 'orderNumber ' . $country['provider_type']]];
But I can't figure out how to create such an array

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Ernest Faizullin, 2019-03-25
@foxxx1234

keyboard accepts rows of lines with buttons. It turns out that the first array is the first row of buttons and so on. Moreover, if you specify 2 buttons in one of the rows of buttons, they will stretch along the width of the body of the messenger by 50% width. Or if you put 4 buttons in one row, they will be 25% each

$keyboard = [];

$1stButtonsLine = ['Раз', 'Два', 'Три'];
$2ndButtonsLine = ['Четыре', 'Пять', 'Шесть']

array_push($keyboard, $1stButtonsLine);
array_push($keyboard, $2ndButtonsLine);

in this example there will be 2 rows with buttons with a width of 33%

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question