I have a query that populates an array. If no results are found it crashes the page with ‘Unidentified index’ messages because the array isn’t built.
I would like to set an IF !results then populate the array with static results, but it’s not working. I have tried many syntax for
if (!mysql_num_rows($result) )
if( mysql_num_rows($result) == 0 )
if(!mysql_num_rows($result) || mysql_num_rows($result) == 0) nothing works.
HELP!
— Controller Code —
// Build the list of services
$sql = “SELECT TS.id, TS.servicename, TSC.name as servicecategoryname
FROM tblservice TS
INNER JOIN tblservicecategory TSC ON TSC.id=TS.categoryid
ORDER BY TSC.name”;
$result = mysqli_query($link, $sql);
if (!mysql_num_rows($result) )
{
$services[] = array(‘id’ => ‘0’, ‘servicename’ => ‘No service’, ‘servicecategoryname’ => ‘No category’);
}
while ($row = mysqli_fetch_array($result))
{
$services[] = array(‘id’ => $row[‘id’], ‘servicename’ => $row[‘servicename’], ‘servicecategoryname’ => $row[‘servicecategoryname’]);
}