I am writing a Telegram-bot

There is a table

name | sum | rain Название1 | 153 | NTS Название2 | 145 | Название3 | 142 | NTS Название4 | 135 | NTS Название5 | 178 | 

So I select rows with the same value, let's say the answer I have SQL finds 2-3 lines, maybe more.

 SELECT `name`, `sum` FROM `buyd` WHERE `rain`='NTS' 

I need to send a formatted message of this type.

 Название1 153 Название3 145 Название4 178 

I assign a permen

 $query = mysql_query("SELECT `name`, `sum` FROM `base` WHERE `rain`='".$rain."'"); $array = mysql_fetch_array($query); $sum = $array[1]; $name = $array[0]; 

I want one variable to print in this format, if at all possible.

Bring in response

 apiRequest("sendMessage", array('chat_id' => $chat_id, "text" => "$name $sum"} 
  • 2
    Show how you output to any format - splash58
  • @ splash58 Completed the question - SloGS
  • while($array = mysql_fetch_array($query)) { echo $array[0] . "\t". $array[1]."\n" } while($array = mysql_fetch_array($query)) { echo $array[0] . "\t". $array[1]."\n" } - splash58
  • There is no conclusion. You simply assign values ​​to two variables - Anton Shchyrov
  • @AntonShchyrov I apologize, did not understand, still added - SloGS

1 answer 1

According to the documentation of the message in the telegram can have basic formatting. In particular, you can send a monospace text. This is what you should use.

 $query = mysql_query("SELECT `name`, `sum` FROM `base` WHERE `rain`='".$rain."'"); $msg = '<pre>'; while ($array = mysql_fetch_array($query)) $msg .= sprintf("%-10s %5s\n", $array[0], $array[1]); $msg .= '</pre>'; apiRequest("sendMessage", array('chat_id' => $chat_id, "text" => $msg)); 
  • Thank you all very much, figured it out, very helpful! - SloGS
  • and how else can you use the same array in order to display inline buttons with the same texts? How many lines, so many buttons, of the form [key1], [key2] - SloGS