D
D
Dmitry Baskakov2018-03-14 12:27:47
PHP
Dmitry Baskakov, 2018-03-14 12:27:47

The script is behaving very strangely. What to do if everything is taken into account in the condition, but it turns out not at all?

Hello friend. If you wandered here, then here is the code:

case "catalog":
                    $number_of_page = (int)$callback_data[1];
                    $catalog = $parser->catalog();
                    $catalog_count = count($catalog);
                    $catalog = array_slice($catalog,$number_of_page,1);
                    $img = $catalog[0]["img"];
                    $title = $catalog[0]["title"];
                    $link = str_replace(["http://","https://"],"",$catalog[0]["link"]);
                    $next_text = "\xE2\x96\xB6";
                    $prev_text = "\xE2\x97\x80";
                    $next = $number_of_page+1;
                    $prev = $number_of_page-1;
                    $buttons_keys = [
                            ["text" => $prev_text, "callback_data" =>"catalog_".$prev],
                            ["text" => "Подробнее", "url" =>"$link"],
                            ["text" => $next_text, "callback_data" =>"catalog_".$next],
                    ];
                    $i = (int)0;
                    if($number_of_page <= $i){
                        unset($buttons_keys[0]);
                        sort($buttons_keys);
                    }elseif($number_of_page >= ($catalog_count-1)){
                        unset($buttons_keys[2]);
                        sort($buttons_keys);
                    }
                    if($number_of_page != $i){
                        $telegram->deleteMessage([
                            "chat_id" => $callback_chat_id,
                            "message_id" => $callback_message_id,
                        ]);
                    }
                    $buttons = [
                        $buttons_keys,
                    ];
                    $keyboard = json_encode(["inline_keyboard"=>$buttons]);
                    $telegram->sendPhoto([
                        "chat_id" => $callback_chat_id,
                        "photo" => $img,
                        "parse_mode" => "Markdown",
                        "reply_markup" => $keyboard,
                        "caption" => "*$title*",
                    ]);
                    break;

By the way, $callback_data[1] = 1, and all other values ​​are taken from the site - everything is working.
The problem is that $number_of_page is not included in the conditions and the posts are not deleted.
Moreover, only when $callback_data[1] = 1 are not deleted. And at 2,3,0, etc. - deleted
A, well, if it matters, then this is a telegram bot. It uses its own library. Working methods - tested.
If this data is enough, then tell me where the error is. Already n'e (about an hour) number of minutes I sit and do not see

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
doublench21, 2018-03-14
@doublench21

if($number_of_page <= $i){ ... }
if($number_of_page != $i){ ... }

If $number_of_page < $i, then it will match both conditions. Is this normal for you?

N
Nurlan, 2018-03-14
@daager

Before if($number_of_page != $i){var_dump, dump both variables and look at the result.

D
Dmitry Baskakov, 2018-03-14
@dmitrybascacov

Topic closed. I'm blind and inattentive you know who. - forgot to add one exception

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question