There are two files, index.php and open.php. The first page itself, the second contains SELECT itself. The reason why is this: for testing in documents. If something is written incorrectly or incorrectly, I apologize in advance.

Pieces of code:

<div class="part"> <div class="content"> <a href="open.php"><img src="pic/example.png"/></a> Name1 </div> <div class="content"> <a href=""><img src="pic/example.png"/></a> Name2 </div> <div class="content"> <a href=""><img src="pic/example.png"/></a> Name3 </div> <div class="content"> <a href=""><img src="pic/example.png"/></a> Name4 </div> <div class="content"> <a href=""><img src="pic/example.png"/></a> Name5 </div> </div> 

  <?php require("connect.php"); try { $pdo = new PDO($dsn, $user, $pass, $options); } catch (\PDOException $e) { throw new \PDOException($e->getMessage(), (int)$e->getCode()); } $data = $pdo->query('SELECT * FROM Partners WHERE NAME="Name" AND STAR="2" AND COLOR="Red"'); while ($oneRow = $data->fetch()){ echo '<br/>'.'Name: '.$oneRow['NAME'].'<br/>'.'Star:'.$oneRow['STAR']. '<br/>'.'Level: '.$oneRow['LEVEL'].'<br/>'.'Color: '.$oneRow['COLOR']; } ?> 

One thing interests, how can you make it so that when you click on a picture, SELECT would work, but under a certain click. For example: There is a click on the picture with the name2 signature, SELECT is triggered, but it changes the WHERE NAME = "Name" to NAME = "Name2". Is it possible? If so, is it possible without JS?

I am not very good at programming, so my approach is probably not correct, if so, I will be grateful for any help :)

  • You can wrap each picture into a form, but it is better not to do so. - Serhii
  • What does it mean to "work", what should change on the screen after receiving the data? If for example a transition to a new page in which everything will be about Name2, then you need to pass a request in a request to a parameter like <a href='test.php?name=Name2'> and in php code, use this parameter from $_GET['name'] and make a request to the database as here php.net/manual/ru/pdostatement.execute.php in example 2. If the page should not be overloaded then do about the same thing through ajax - Mike
  • @Mike By "triggering" I had its launch, the action, maybe there is some more precise definition, but unfortunately I don’t know it. I would also like to clarify how to bind $ _GET and query in database with each other? I just can not understand. - Koruya Shigiwara 2:24 pm
  • To connect simply $sth=$dbo->prepare('select * from .... where NAME=? ...'); $sth->execute(array($_GET['name'])); $sth=$dbo->prepare('select * from .... where NAME=? ...'); $sth->execute(array($_GET['name'])); php.net/manual/ru/pdo.prepare.php - Mike 2:38 pm

1 answer 1

I think if without JS, then you can put a path to open.php with GET parameters in each link like <a href="yoursite.com/open.php?docName=Name"> and check $ _GET ['docName in open.php ']. Next, substitute this variable in the request. We forget that the variable should be at least thrown through placeholders ( http://php.net/manual/ru/pdo.prepare.php )

  • What is meant by "docName"? Did not quite understand this moment. - Koruya Shigiwara 2:23 pm
  • in line after? Key-value pairs are transmitted, on the server side, the Name value is available on the docName key - $ _GET ['docName'] - LeshaZ