J
J
JaguXam2016-01-16 04:17:13
PHP
JaguXam, 2016-01-16 04:17:13

How to output an array and immediately write to an array?

I'm a so-so programmer...) I don't even know how to explain it. Basically, here is the code.

$s_srv = mysql_query("SELECT * FROM ms_gameservers order by id LIMIT 0,2");
while($srv = mysql_fetch_assoc($s_srv)) 
    {
    $servers = array('IDSERVER' => array('cssource', "$srv[s_ip]", "$srv[s_port]"),);
    }

Naturally, it is not written to the array, because in the loop it tries to create the array again.
How to make it open and close the array after the loop.
$servers = array(

);

And in the cycle itself there was only this.
'IDSERVER' => array('cssource', '185.77', 27015),
'IDSERVER2' => array('cssource', '185.79.20.93', 27016),

I will be very grateful for the answer.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Stalker_RED, 2016-01-16
@JaguXam

$servers = array(); // создаем пустой массив
// помните, что mysql_query уже не работает в php верси 7 и выше.
// Пора переходить на mysqli, PDO или что-нибудь другое.
$s_srv = mysql_query("SELECT * FROM ms_gameservers order by id LIMIT 0,2");
while($srv = mysql_fetch_assoc($s_srv)) 
{
    // каждую запись дописываем в массив
    $servers[] = array('cssource', $srv['s_ip'], $srv['s_port']); 
}

W
Walt Disney, 2016-01-16
@ruFelix

$servers[] = array(...);

J
JaguXam, 2016-01-16
@JaguXam

Haven't tried it yet. Does not help.
In the same place, as far as I understand, one more bracket should close it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question