У меня есть множество различных типов популяций, и я хотел бы сохранить даты в моей базе данных в соответствии с количеством людей в каждой популяции. переопределить ">// 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);
var_dump($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
Я сталкиваюсь с проблемой, чтобы правильно выполнить свои условия IF и Elseif с PHP [закрыто] ⇐ Php
Кемеровские программисты php общаются здесь
1739786858
Anonymous
У меня есть множество различных типов популяций, и я хотел бы сохранить даты в моей базе данных в соответствии с количеством людей в каждой популяции. переопределить ">// 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);
var_dump($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
Подробнее здесь: [url]https://stackoverflow.com/questions/79444472/i-face-a-problem-to-execute-properly-my-if-and-elseif-conditions-with-php[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия