$data = $stmt->fetchAll(PDO::FETCH_UNIQUE);
$data = $pdo->query("SELECT id, name FROM table")fetchAll(PDO::FETCH_KEY_PAIR);
$sql = "SELECT id, city_name FROM city where id = ?";
$stmt = $pdo->prepare($sql);
$stmt->execute([$_GET['sch']]);
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
include 'db.php';
$data = $pdo->query("SELECT id FROM city LIMIT 10")->fetchAll();
?>
<form>
<div class="form-group">
<label for="search_word">Поиск</label>
<select class="form-control" name="sch">
<?php foreach ($data as $row): ?>
<option><?=$row['id']?></option>
<?php endforeach ?>
</select>
</div>
<input type="submit" class="btn btn-default">Поиск</button>
</form>
<?php
if (!isset($_GET['sch'])) {
die("Выберите значение");
}
$sql = "SELECT id, city_name FROM city where id = ?";
$stmt = $pdo->prepare($sql);
$stmt->execute([$_GET['sch']]);
$data = $stmt->fetchAll();
?>
<?php if ($data) : ?>
<table class="table table-striped"><tr><th>ID</th><th>Город</th></tr>
<?php foreach ($data as $row): ?>
<tr><td><?=$row["id"]?></td><td><?=$row["city_name"]?></td></tr>
<?php endforeach ?>
</table>
<?php else : ?>
echo "0 results";
<?php endif ?>
$host = '127.0.0.1';
$db = 'add';
$user = 'root';
$pass = 'qwerty';
$charset = 'utf8mb4';
$options = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
];
$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
try {
$pdo = new PDO($dsn, $user, $pass, $options);
} catch (\PDOException $e) {
throw new \PDOException($e->getMessage(), (int)$e->getCode());
}
if(isset($_POST['add']))
{
$fm = trim($_POST['fm']);
$name = trim($_POST['name']);
$ot = trim($_POST['ot']);
$phone = trim($_POST['phone']);
$adres = trim($_POST['adres']);
$stmt = $pdo->prepare("INSERT INTO clinika (fm, name, ot, phone, adres) VALUES (?,?,?,?,?)");
$stmt->execute([$fm, $name, $ot, $phone, $adres]);
echo "Новость уcпешно добавлена!";
}
$_SESSION['test'] = isset($_POST['test']);
$_SESSION['test'] = !empty($_POST['test']);
$begin = new DateTime( '2019-01-10' );
$end = new DateTime( '2019-02-10');
$end = $end->modify( '+1 day' ); // если надо включительно
$interval = new DateInterval('P1D');
$daterange = new DatePeriod($begin, $interval ,$end);
foreach($daterange as $date){
echo $date->format("Y-m-d") . "\n";
}
$data = $pdo->query("SELECT sector, table.* FROM table")->fetchAll(PDO::FETCH_GROUP);
$sql = "SELECT * FROM `forum_topic` WHERE id = ?";
$topic = mysqli($base, $sql, [$id])->get_result()->fetch_assoc();
$sql = "SELECT * FROM `profile` WHERE id = ?";
$profile = mysqli($base, $sql, [$topic['uid']])->get_result()->fetch_assoc();
$sql = "SELECT * FROM forum_topic, t profile p WHERE p.id=t.uid AND t.id = ?";
$topic = mysqli($base, $sql, [$id])->get_result()->fetch_assoc();
function mysqli_assoc($mysqli, $sql, $params) {
return mysqli($mysqli, $sql, $params)->get_result()->fetch_assoc();
}
вывести из таблицы где нет значений второй таблицы
SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.id=t2.id WHERE t2.id IS NULL
SELECT id FROM users u LEFT JOIN user_dating ud ON ud.user_id=u.id
WHERE ud.user_id IS NULL
AND u.photo='1' and u.gender='1'
ORDER BY rand()