This is body.php. To get all the lines from the array, the getPosts function responds, it also sets the id in the link.

<?require_once ("functions/bd_connect.php");?> <?require_once ("functions/bd_matches.php");?> <section class="box" style="background-color:#edf3fe; width: 850px; height: 100%; padding-left: 23px; float: left"> <div class="title" style="background: url(img/my_trades.png) no-repeat; text-transform: none;"> Trades</div> </section> <section class="box" style="background-color:#d7d7d7; width: 850px; height: 100%; padding-left: 23px; padding-right: 23px; float:right"> <div class="title" style="background: url(img/my_bets.png) no-repeat;text-transform: none; "> Bets</div> <article class="standard" id="bets" style="margin-top: 40px;"> <?$posts = getPosts();?> <!-- Главные строки !--> <? foreach($posts as $post): ?> <!-- Главные строки !--> <div class="matchmain"> <div class="matchheader"> <div class="whenm"> <?=$post['time']?> <span style="font-weight: bold; color: rgb(209, 33, 33);"/> </div> <div class="eventm"><?=$post['event']?></div> </div> <div class="match" style="background-image:url('img/event/<?=$post['event']?>.jpg');"> <div class="matchleft"> <a href="/match.php?m=<? echo $post['id']?>"> <div style="width: 45%; float: left; text-align: right;"> <div class="team" style="float: right;"><img src="img/teams/<?=$post['team 1']?>.jpg"></img></div> <div class="teamtext"> <b><?=$post['team 1']?></b> <br/> <i>19%</i> </div> </div> <div style="width: 10%; float: left; text-align: center; margin-top: 0.6em; "> <span class="format"><?=$post['bon']?></span> <br/> vs </div> <div style="width: 45%; float: left; text-align: left;"> <div class="team" style="float: left;";><img src="img/teams/<?=$post['team 2']?>.jpg"></img></div> <div class="teamtext"> <b><?=$post['team 2']?></b> <br/> <i>81%</i> </div> </div> </a> </div> </div> </div </div> <? endforeach; ?> <!-- Главные строки !--> </article> </section> 

This is match.php

 <? $link = mysqli_connect('localhost', 'root', '', 'my_site_1'); if(mysqli_connect_errno()) { echo 'Ошибка подключения к БД ('.mysqli_connect_errno().'): '.mysqli_connect_error(); exit(); } ?> <?require_once ("functions/bd_matches.php");?> <body> <?$matches = getMatch(strip_tags($_GET['m'])); foreach($matches as $match) { echo $match['team 1']; } ?> 

And this is bd_matches.php

 <? function getPosts() { global $link; $sql = "SELECT * FROM `matches` ORDER BY id DESC LIMIT 0, 21"; $result = mysqli_query($link, $sql); $posts = mysqli_fetch_all ($result, 1) ; return $posts; } function getMatch($m) { global $link; if($m) { echo 'All is good'; echo $m; $where = "WHERE 'id' = ".$m; $sql = "SELECT * FROM `matches` $where ORDER BY 'id'"; $result = mysqli_query($link, $sql); $matches = mysqli_fetch_all($result, 1) ; return $matches; } } ?> 

And this is a database

 -- phpMyAdmin SQL Dump -- version 3.5.1 -- http://www.phpmyadmin.net -- -- Хост: 127.0.0.1 -- Время создания: Янв 13 2017 г., 22:38 -- Версия сервера: 5.5.25 -- Версия PHP: 5.3.13 SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; SET time_zone = "+00:00"; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8 */; -- -- База данных: `my_site_1` -- -- -------------------------------------------------------- -- -- Структура таблицы `matches` -- CREATE TABLE IF NOT EXISTS `matches` ( `id` int(11) NOT NULL AUTO_INCREMENT, `event` varchar(255) NOT NULL, `bon` varchar(3) NOT NULL, `team 1` varchar(255) NOT NULL, `team 2` varchar(255) NOT NULL, `time` time NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=41 ; -- -- Дамп данных таблицы `matches` -- INSERT INTO `matches` (`id`, `event`, `bon`, `team 1`, `team 2`, `time`) VALUES (2, 'DreamHack', 'BO3', 'G2', 'Fnatic', '14:53:00'), (3, 'Dolphin SEA', 'BO1', 'G2', 'Fnatic', '18:13:00'), (8, 'Dolphin SEA', 'BO1', 'G2', 'Fnatic', '18:13:00'), (11, 'Dolphin SEA', 'BO1', 'G2', 'Fnatic', '18:13:00'), (13, 'Dolphin SEA', 'BO1', 'G2', 'Fnatic', '18:13:00'), (14, 'Dolphin SEA', 'BO1', 'G2', 'Fnatic', '18:13:00'), (16, 'Dolphin SEA', 'BO1', 'G2', 'Fnatic', '18:13:00'), (19, 'ESEA', 'BO1', 'G2', 'Fnatic', '18:13:00'), (22, 'DreamHack', 'BO3', 'G2', 'Fnatic', '14:53:00'), (23, 'ESEA', 'BO1', 'G2', 'Fnatic', '18:13:00'), (24, 'DreamHack', 'BO3', 'G2', 'Fnatic', '14:53:00'), (25, 'DreamHack', 'BO3', 'G2', 'Fnatic', '14:53:00'), (26, 'DreamHack', 'BO3', 'G2', 'Fnatic', '14:53:00'), (27, 'DreamHack', 'BO3', 'G2', 'Fnatic', '14:53:00'), (28, 'DreamHack', 'BO3', 'G2', 'Fnatic', '14:53:00'), (29, 'DreamHack', 'BO3', 'G2', 'Fnatic', '14:53:00'), (30, 'DreamHack', 'BO3', 'G2', 'Fnatic', '14:53:00'), (31, 'King of Nordic', 'BO1', 'G2', 'Fnatic', '18:13:00'), (32, 'DreamHack', 'BO3', 'G2', 'Fnatic', '14:53:00'), (33, 'King of Nordic', 'BO1', 'G2', 'Fnatic', '18:13:00'), (34, 'ESEA', 'BO3', 'Fnatic', 'G2', '14:53:00'), (35, 'ESEA', 'BO1', 'Na''Vi', 'VP', '14:53:00'), (36, 'WESG', 'BO3', 'Selfless', 'G2', '17:55:00'), (37, 'ESEA', 'BO7', 'Epsilon', 'LDLC', '14:24:00'), (38, 'King of Nordic', 'BO1', 'Fnatic', 'Rogue', '13:33:00'), (39, 'ESEA', 'BO5', 'Na''Vi', 'VP', '16:23:00'); /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; 
  • so everything works correctly for you, you don’t print the result of the select to the database - L. Vadim
  • how to withdraw? - Anatoly
  • $ result = mysqli_query ($ link, $ sql); print_r ($ result); - L. Vadim
  • And so not an array? - Anatoly
  • while ($ row = mysqli_fetch_array ($ result)) {echo $ row; } - L. Vadim

1 answer 1

 function getMatch($m) { global $link; if($m) { echo 'All is good<br>'; echo $m; $sql = "SELECT * FROM matches WHERE id=$m"; $result = mysqli_query($link, $sql); $matches = mysqli_fetch_all($result, 1) ; return $matches; } } $matches = getMatch(strip_tags($_GET['m'])); //print_r($matches); foreach($matches as $match) { echo $match['event'] . " : " . $match['bon'] . " : " . $match['team 1']; }