Задать вопрос
  • Как распарсить данные из массива?

    alsolovyev
    @alsolovyev
    ¯\_(ツ)_/¯ Enjoy life, Eat well & Laugh often
    А что распарсить то надо?
    Вам приходит строка:
    <Sum> [stat]player_ammo_restored  = 425339
    <Sum> [stat]player_climb_assists  = 17154
    <Sum> [stat]player_climb_coops  = 9321
    <Sum> [stat]player_damage  = 489573500
    <Sum> [mode]PVE [stat]player_deaths  = 22793
    <Sum> [mode]PVP [stat]player_deaths  = 107455
    <Sum> [class]Rifleman [mode]PVP [stat]player_headshots  = 38150
    <Sum> [class]Medic [mode]PVE [stat]player_headshots  = 40388
    <Sum> [class]Medic [mode]PVP [stat]player_headshots  = 4271
    <Sum> [class]Recon [mode]PVE [stat]player_headshots  = 129160
    <Sum> [class]Recon [mode]PVP [stat]player_headshots  = 5423
    ....


    Нужен array?
    const arr = json.full_response.split('\n');
    
    /*
    [0 … 99]
      0: "<Sum> [stat]player_ammo_restored  = 425339"
      1: "<Sum> [stat]player_climb_assists  = 17154"
      2: "<Sum> [stat]player_climb_coops  = 9321"
      3: "<Sum> [stat]player_damage  = 489573500"
      4: "<Sum> [mode]PVE [stat]player_deaths  = 22793"
      5: "<Sum> [mode]PVP [stat]player_deaths  = 107455"
      6: "<Sum> [class]Rifleman [mode]PVP [stat]player_headshots  = 38150"
      7: "<Sum> [class]Medic [mode]PVE [stat]player_headshots  = 40388"
      8: "<Sum> [class]Medic [mode]PVP [stat]player_headshots  = 4271"
      9: "<Sum> [class]Recon [mode]PVE [stat]player_headshots  = 129160"
      10: "<Sum> [class]Recon [mode]PVP [stat]player_headshots  = 5423"
      11: "<Sum> [class]Engineer [mode]PVE [stat]player_headshots  = 137344"
      12: "<Sum> [class]Engineer [mode]PVP [stat]player_headshots  = 17705"
      13: "<Sum> [class]Rifleman [mode]PVE [stat]player_headshots  = 429473"
    */


    Нужен только Medic?
    arr.forEach((el) => {
      if (el.indexOf('Medic') >= 0) {
        window.console.log(el);
      }
    });
    
    /* 
    <Sum> [class]Medic [mode]PVE [stat]player_headshots  = 40388
    <Sum> [class]Medic [mode]PVP [stat]player_headshots  = 4271
    <Sum> [class]Medic [mode]PVP [stat]player_hits  = 286872
    <Sum> [class]Medic [mode]PVE [stat]player_hits  = 824486
    <Sum> [class]Medic [mode]PVE [stat]player_melee_headshots  = 133
    <Sum> [class]Medic [mode]PVP [stat]player_melee_headshots  = 37
    <Sum> [class]Medic [mode]PVE [stat]player_playtime  = 17714490
    <Sum> [class]Medic [mode]PVP [stat]player_playtime  = 12876754
    */
    Ответ написан
    Комментировать
  • Вывод данных из БД через DropDown или список?

    coderisimo
    @coderisimo
    // для начала надо подключиться к базе данных
    mysql_connect('hostname', 'username', 'password'); // пароль, логин , хост нейм для подключения к базе
    mysql_select_db('database-name'); // название базы
    // если в процессе подключения к БД есть ошибки - нужно разобраться и 
    // исправить (в тектсе ошибки будет подсказка)
    
    $sql = "SELECT  user_id FROM users";
    $result = mysql_query($sql);
    
    echo "<select name='user_id'><option>Выбор ответсвенного</option>";
    while ($row = mysql_fetch_array($result)) {
        echo "<option value='" . $row['user_id'] . "'>" . $row['user_id'] . "</option>";
    }
    echo "</select>";
    Ответ написан
    2 комментария