Я сталкиваюсь с проблемой, чтобы правильно выполнить мои условия if и elseif с phpPhp

Кемеровские программисты php общаются здесь
Ответить
Anonymous
 Я сталкиваюсь с проблемой, чтобы правильно выполнить мои условия if и elseif с php

Сообщение Anonymous »

Все, я надеюсь, у вас все хорошо, у меня есть множество различных типов популяций, и я хотел бы сохранить данные в моей базе данных в соответствии с количеством людей в каждой популяции. < /p>
// To have the number of persons in each population, i make this
// first request:

$sel =$pdo->prepare("SELECT * FROM big_group WHERE group = ? and age=?");

$sel->setFetchMode(PDO::FETCH_ASSOC);
$sel->execute(array(1, 40));
$tab = $sel->fetchAll();

$population1 = count($tab);
echo $population1;
// there are 7 groups so i make this same request 7times, and i put them in a
// same key value array, in the end i have:

$array_of_populations = [

1 = > $population1,
2 = > $population2,
3 = > $population3,
4 = > $population4,
5 = > $population5,
6 = > $population6,
7 = > $population7,
]; // Since i want to classify the populations from the smallest to the biggest
// i use asort //function
asort($array_of_populations);

// Next i use retrieve the key of the value with the smallest value with a short
// loop

$i = 0;
foreach ($array_of_population as $Group = > $number_of_persons) {
if ($i == 1) break;
$i++;
$the_smallest_group = $Group;
// So far so good,But now i want to save data in my database and it doesn't
// work properly,here is //my request:

if ($the_smallest_group = 1) {
$req = $pdo->prepare("SELECT link FROM images_group1 ORDER BY id DESC ");
$req->execute();
$req->setFetchMode(PDO::FETCH_ASSOC);
$image_of_group =
$req->fetch(); // here i selected an image from the group 1 in a table
// and i insert it in another table

$req = $pdo->prepare(
"UPDATE final_history SET image_of_groupe=? WHERE date_of_save>?");
$req->execute([ $image_group1['link'], $last_treatment ]);
}
elseif($the smallest_group = 2) {
$req = $pdo->prepare("SELECT link FROM image_group2 ORDER BY id DESC ");
} // and i make the same request for the other groups ,ex:
// elseif($the_smallest_group3=3){$req=$pdo->prepare("SELECT link FROM
// images_group3 ORDER BY id DESC ")
; // etc.....}
// here is my problem,whatever the value of '$the_smallest_group'(4;5;6
// etc...),it's always the //images of the first group that are selected and
// inserted in the table of my database and i //don't know why(i even tried ==
// instead of = like if($the_smallest_group==1){...},thanks for //your help


Подробнее здесь: https://stackoverflow.com/questions/794 ... s-with-php
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Php»