I have this piece of code:
$i=0;
while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)){
*(line 133)* if (array_search("SUCCESS", $row) != false) {
echo "<tr class='success'>";
}
elseif (array_search("ERROR", $row) != false) {
echo "<tr class='danger'>";
}
else {
echo "<tr>";
}
foreach ($row as $rowData) {
if ($rowData == "SUCCESS") {
echo "<td><span class='mdi-navigation-check'></span></td>";
}
elseif ($rowData == "ERROR") {
echo "<td><span class='mdi-navigation-close'></span></td>";
}
else {
if (gettype($rowData) == "object") {
echo "<td>" . $rowData->format('Y-m-d H:i:s') . "</td>";
} else {
echo "<td>" . $rowData . "</td>";
}
}
}
if (isset($row["cMsgID"])) {
echo "<td><a href='#' onclick='window.open(\"/monitor/templates/history.php?cMsgID=" . $row["cMsgID"] . "\", \"history\", \"status=1, toolbar=1 width=800px, height=400px\")'>History</a></td>";
}
echo "</tr>";
$i++;
}
But when I add a second condition to the while loop the $row
variable becomes a boolean true
:
$i
while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC) && $i < 10){
*same code as above*}
First php error message: Warning: array_search() expects parameter 2 to be array, boolean given in C:\wamp32bit\www\monitor\templates\mainContent.php on line 133
I have searched for this problem but all of them were related to wrong syntax or the conditions excluding each other.
Why does this happen?