Ich bin vor einem Problem, um meine if und sonst if -Bedingungen mit PHP [geschlossen] richtig auszuführen.Php

PHP-Programmierer chatten hier
Anonymous
 Ich bin vor einem Problem, um meine if und sonst if -Bedingungen mit PHP [geschlossen] richtig auszuführen.

Post by Anonymous »

Jeder, ich hoffe, es geht Ihnen gut, ich habe eine Reihe verschiedener Populationsarten und möchte Daten in meiner Datenbank entsprechend der Anzahl der Personen in jeder Population speichern. < /p>

Code: Select all

// 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

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post