L
L
l0lkek2021-11-16 18:56:19
AJAX
l0lkek, 2021-11-16 18:56:19

How to display information on button click?

Good day.
I just took up PHP and wanted to implement this mechanism, the essence of which is that there are 3 blocks. Suppose there are two elements in the first block, and if you select the second element, then four elements are displayed in the second block, and if you select the first element, then two elements are displayed in the second block. The same things happen with the second block, depending on what we choose, the corresponding information is displayed in the table of the third block. There are 0 ideas in my head how to implement this, so I ask for your help. Is it possible to implement this only in PHP? If this cannot be done only in PHP, then please let me know what I may need for this. And maybe someone has similar examples, then please share :). Thanks in advance!
6193d176e6f83658252265.png

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Andrey Korekhov, 2021-11-17
@l0lkek

If you still use JS, then try ajax.
In short, when you click on the Ajax button, the script will send the data you specified to the backend, where the php handler will prepare the necessary data, for example, select the necessary rows from the database. (in the same place it’s better to lay everything out right away so that you don’t write it through js later) and send them back to the user and display them in the block you specified.
This method is still more preferable than throwing all possible options on the page at once and then filtering them. (both the size of the page itself, and it is possible to display some kind of personal, private data in the general stream)
If without using JS
Then.
1. We display all the data on the page with the obligatory indication of block IDs.
2. We make the buttons links with the indication of the id of the associated block Button
3. In CSS, we prescribe the hiding of all sub-elements - display: none
4. In CSS, we use the pseudo-class :target {display:block;}

span{
    display: none;
}

span#element:target{
    display: block;
}

Logic
When the button is clicked, the element with the ID specified in it receives the :target pseudo class, which can be used in css
. Of the disadvantages - you cannot hang more than 1 element on such a chain. Those. if it is necessary to open some next one from the "target" of the block, then the next one will open, but for the current one the target will fly off and it will not be visible again.

S
Stalker_RED, 2021-11-16
@Stalker_RED

Php runs on the server, and does not know where the user is clicking in the browser.
In order for php to know about clicks, these must be clicks on links or form buttons (well, or use js, but you want pure php).
Let's say you have a page with the address /list.php,
You can add a couple of links on it, to which a parameter has been added, indicating how many elements to show

<a href="/list.php?count=2">показывать 2</a>
<a href="/list.php?count=4">показывать 4</a>

Now in php you can check this setting:
$cnt = filter_input(INPUT_GET, 'count', FILTER_SANITIZE_NUMBER_INT) 
   ?: 1;  // по умолчанию 1

  echo "показываем $cnt элементов" ;

V
Vladimir Yasankin, 2021-11-17
@jsnk

When generating code in php, you display all blocks with display=none, except for those that need to be shown after loading. When you select an element, you set and reset the display as needed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question