Hola, tengo una peticion ajax en la que estoy tratando de hacer un ciclo foreach porque asi lo necesito, sin embargo al ejecutar la peticion me devuelve el siguiente error:
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\CustomerInsightSystem\php\procesar .php on line 13
mi codigo es el siguiente:
Código PHP:
<?php
include('conexion.php');
$dato = $_POST['dato'];
//EJECUTAMOS LA CONSULTA DE BUSQUEDA
if ($dato != '') {
$registro = pg_query($con, "SELECT cm.companyName as companyname, ca.address as address, ca.website as website, ca.segmentID as segmentID, sc.segmentName as segment FROM company_main cm, company_attributes ca, segment_catalog sc WHERE ca.localName = cm.companyName and ca.segmentID = sc.segmentID and cm.companyName LIKE '%$dato%' OR ca.website LIKE '%$dato%'");
//CREAMOS NUESTRA VISTA Y LA DEVOLVEMOS AL AJAX
echo '<table class="table table-stripped table-responsive table-hover table-condesed" style="color: #FFF;">
<tr style="background-color: #000;">
<th>Company</th>
<th>Address</th>
<th>Web page</th>
<th>Segment</th>
</tr>';
$i = 1;
foreach ($registro as $registro2) {
echo '<form action="" method="post">
<tr>
<td><a href="recordsMaster.php?details=companyname" id="companyname" name="companyname$i">'.$registro2['companyname'].'</a></td>
<td id="address$i" name="address">'.$registro2['address'].'</td>
<td id="website$i" name="website">'.$registro2['website'].'</td>
<td id="segment$i" name="segment">'.$registro2['segment'].'</td>
</tr></form>';
$i++;
}
}else{
echo '<tr>
<td colspan="6">No records found</td>
</tr>';
}
echo '</table>';
?>
en el id estoy haciendo un aumento con la variable $i, pero tenga el aumento o no lo tenga, el resultado es el mismo, sigue enviando el mismo error.
Alguien me puede ayudar a identificar el error por favor?
Agradezco su apoyo