I have a form in html that submits some values and a php code performs a query that returns a table:
<?php
echo "<table style='border: solid 1px black;'>";
echo "<tr>
<th>F1</th>
<th>R1</th>
<th>R2</th>
<th>R3</th>
<th>R4</th>
<th>R5</th>
<th>F6</th>
<th>F7</th>
<th>F8</th>
<th>F9</th>
</tr>";
class TableRows1 extends RecursiveIteratorIterator {
function __construct($it1) {
parent::__construct($it1, self::LEAVES_ONLY);
}
function current() {
return "<td style='width: 70px;'>" . parent::current(). "</td>";
}
function beginChildren() {
echo "<tr>";
}
function endChildren() {
echo "</tr>" . "
";
}
}
if( isset($_POST['submit']) )
{
$feature = $_POST['R1'];
$feature2 = $_POST['R2'];
$feature3 = $_POST['R3'];
$feature4 = $_POST['R4'];
$feature5 = $_POST['R5'];
};
$feature = $_POST['R1'];
$feature2 = $_POST['R2'];
$feature3 = $_POST['R3'];
$feature4 = $_POST['R4'];
$feature5 = $_POST['R5'];
$values = [$feature, $feature2, $feature3, $feature4, $feature5];
$servername = "";
$username = "";
$password = "";
$dbname = "";
try {
$conn1 = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn1->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt1 = $conn1->prepare(
"SELECT
.......
;")
;
$stmt1->bindParam(1, $feature, PDO::PARAM_INT);
$stmt1->bindParam(2, $feature2, PDO::PARAM_INT);
$stmt1->bindParam(3, $feature3, PDO::PARAM_INT);
$stmt1->bindParam(4, $feature4, PDO::PARAM_INT);
$stmt1->bindParam(5, $feature5, PDO::PARAM_INT);
$stmt1->bindParam(6, $feature, PDO::PARAM_INT);
$stmt1->bindParam(7, $feature2, PDO::PARAM_INT);
$stmt1->bindParam(8, $feature3, PDO::PARAM_INT);
$stmt1->bindParam(9, $feature4, PDO::PARAM_INT);
$stmt1->bindParam(10, $feature5, PDO::PARAM_INT);
$stmt1->execute();
// set the resulting array to associative
$result1 = $stmt1->setFetchMode(PDO::FETCH_ASSOC);
foreach(new TableRows1(new RecursiveArrayIterator($stmt1->fetchAll())) as $k1=>$v1) {
echo $v1;
}
}
catch(PDOException $e1) {
echo "Error: " . $e1->getMessage();
}
$conn1 = null;
echo "</table>";
I am trying to echo some message if the value of the first field F1 (in the resulting table) is null, I have the intuition that I should assign the value to a variable but I don't know how to achieve it.
Note: F1 is not one of the values submitted in the form.
Thanks
question from:
https://stackoverflow.com/questions/65943119/how-to-assign-a-php-query-result-table-value-to-a-variable 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…