Answer the question
In order to leave comments, you need to log in
How to write a prepared query?
Decided to optimize requests.
I'm trying to write prepared queries. For some reason it doesn't come out.
Data types in table
id - int
time - int
ticker - char
//Получаем данные
$mysqli_request="SELECT `time`,`$column_value_from_base` FROM `$table_name` WHERE `time`>'$begin_time' AND `time`<'$end_time' AND `ticker`='$ticker'";
$mysqli_result=$mysqli->query($mysqli_request) or die ($mysqli->error);
$mysqli->close;
//Выводим их в цикле
$num_rows = $mysqli_result->num_rows;
//Заполняем массив данных
for($num_rows; $num_rows>0; $num_rows--)
{
$row = $mysqli_result->fetch_assoc();
$time=$row['time'];
}
//и далее ещё код....
//Подготавливаемый запрос
$stmt = $mysqli->prepare("SELECT `time`,? FROM $table_name WHERE `time`>? AND `time`<? AND `ticker`=?");
$stmt->bind_param('siis',$column_value_from_base,$begin_time,$end_time,$ticker);
$stmt->execute();
$mysqli_result = $stmt->get_result();
$mysqli->close; //Принудительно закрываем соединение (оптимизация)
$stmt->close; //Принудительно закрываем запрос (оптимизация)
//Выводим их в цикле
$num_rows = $mysqli_result->num_rows;
//Заполняем массив данных
for($num_rows; $num_rows>0; $num_rows--)
{
$row = $mysqli_result->fetch_assoc();
$time=$row['time'];
}
//и далее ещё код....
Answer the question
In order to leave comments, you need to log in
roughly threw rubber)
codepen.io/anon/pen/KdBJew
HTML:
<header>
<div class="logo">
<h1>Logo</h1>
</div>
<div class="right-header">
<div class="name">
<h2>name</h2>
</div>
<div class="description">
<p>description</p>
</div>
</div>
</header>
header {
position: relative;
width: 100%; height: 200px;
outline: 2px solid #000;
}
header, header * {
padding: 0;
margin: 0;
}
.logo {
position:absolute;
outline: 1px solid #000;
width: 200px; height: 200px;
}
.right-header {
position: absolute;
right: 0; top: 0;
width: calc(100% - 200px);
}
.name {
width: 100%;
height: 70px;
outline: 1px solid #000;
right: 0; top: 0;
text-align: center;
}
.description {
width: 100%;
height: 130px;
outline: 1px solid #000;
right: 0; top: 0;
text-align: center;
}
HTML
<header class="header clearfix">
<div class="left"></div>
<div class="right-top"></div>
<div class="right-bottom"></div>
</header>
.left {
float: left;
width: 33%;
height: 300px;
background: green;
}
.right-top,
.right-bottom {
float: right;
width: 67%;
}
.right-top {
height: 100px;
background: red;
}
.right-bottom {
height: 200px;
background: blue;
}
.clearfix::after {
display: block;
content: '';
clear: both;
}
Sorry for the long response - thank you so much! Have a nice day!
Placeholders can only substitute values. The names of columns, tables, databases are not substituted.
PS In general, see errno / error after each function.
More or less like this
$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
$stmt = $dbh->prepare("SELECT * FROM table where `time` > ? AND `time` < ? AND ticker = ?");
if ($stmt->execute(array($minTime, $maxTime, $ticker))) {
while ($row = $stmt->fetch()) {
print_r($row);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question