N
N
nepster-web2014-01-01 22:52:59
PHP
nepster-web, 2014-01-01 22:52:59

Changing a table dynamically

We have applications from players to start the game. For example, the game of checkers can be played by 2 people.
The user creates an offer to play and waits for the opponent, when the opponent joins, the user starts the game.
So for example we have a table:

<table id="proposal">
            <thead>
                <tr>
                    <th>№</th>
                    <th>Игрок</th>
                    <th>Опции</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>1</td>
                    <td>Пользователь/или ожидание</td>
                    <td>Действия</td>
                </tr>
                
                <tr>
                    <td>2</td>
                    <td>Пользователь/или ожидание</td>
                    <td>Действия</td>
                </tr>
                
            </tbody>
        </table>

Already generated with sneeze puff puff.
Here we have 1 user created an application and 1 column of the table will be with the data of 1 user, the second column will be with the expectation of 2 players.
Next, for example, an SSE request occurs and returns us data that the 2nd player has joined.
Next, we have SSE queries that check whether the second player has joined. For example, the player joined and the server returned JSON, where there is such an array:
['users'] =  array(
                                    'user' => 'avatar',
                                    'sort' => 0,
                                    'root' => 1,
                                  ),
                        array(
                                    'user' => 'avatar',
                                    'sort' => 1,
                                    'root' => 0,
                                  )

Our task is to add the user data returned by the server to the required one.
That is :
// here we have 1 user who created an order
<tr>
<td>1</td>
<td>Nepster</td>
<td>Up, Down, Kick</td>
</tr>
// here we have user 2 joined
<tr>
<td>2</td>
<td>Here you need to add the [user] value from the array that came from the server </td>
<td>it's more complicated here, the action drain is generated by php</td >
</tr>

But to be honest, I have no idea how you can use it?
And the second moment, when the user who created the application swaps the players (this is true when the game is in pairs).
An array arrives, where there is a sort field, which is responsible for sorting the players
['users'] = array(
'user' => 'avatar',
'sort' => 0,
'root' => 1,
),
array(
'user ' => 'avatar',
'sort' => 1,
);
It was advised to use a plugin for sorting tables or underscorejs.org/#sortBy
But here I also can’t figure out how to link the array that came from the server with the sortBy of this library.
Can anyone please tell me how this can be done?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
svd71, 2014-01-01
@svd71

use something like this .
Its meaning is that such code, when executed by the client in the browser, periodically sends special requests to the server, receives the necessary data from it and changes the content on the page on the fly.

A
Alexander, 2014-01-02
@kryoz

You may need to change the application paradigm to an event-driven one.
Then you won't need to update the views on a timer and create excessive load on the server.
This means that you may have to dig towards long polling, Ratchet, or even go radical and switch to node.js

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question