Answer the question
In order to leave comments, you need to log in
Doesn't output last row from sql table?
There is a stat table with delivery and cost columns (default = 0), I get values from it row by row with a condition (if delivery = 'Mail' and cost=0), after output I make changes to the cost column, and the next time I access the table, it displays the next line that matches the condition.
//Получаю данные заказа для обработки почты
function getOne(){
$conn = connect();
$result = mysqli_query($conn,"SELECT * FROM `stat` WHERE `delivery`='Почта' AND `cost`='0'");
if (mysqli_num_rows($result)>0){
$row= mysqli_fetch_row($result);
$id= $row[0];
$result2 = mysqli_query($conn,"SELECT * FROM `order` WHERE `id`='$id'");
$row = mysqli_fetch_assoc($result) + mysqli_fetch_assoc($result2);
echo json_encode($row);
}
else {
echo "Ошибка в getOne";
}
mysqli_close($conn);
}
Answer the question
In order to leave comments, you need to log in
You should use one query with join:
<?php
function getOne($conn) {
$result = mysqli_query($conn,"
SELECT *
FROM `stat`
JOIN `order` ON `order`.`id` = `stat`.`order_id`
WHERE `delivery`='Почта' AND `cost`='0'"
);
if (mysqli_num_rows($result)>0) {
while ($row = mysqli_fetch_assoc($result)) {
echo json_encode($row);
}
}
else {
echo "Ошибка в getOne";
}
mysqli_close($conn);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question