Hi, could someone point me in the right direction, a solution, or documentation on how best to handle the following situation. The following query runs fine and every thing stores correctly. but I run into situations that a result from the query will not return any results, which is fine, but i then get a foreach error. I need a switch that basically says if no results then output a single status row.
$query = "select c.categories_id, cd.categories_name, c.parent_id
from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd
where c.categories_id = cd.categories_id
and cd.language_id = '" . (int)$_SESSION['languages_id'] . "'
and c.categories_status != '0'
and c.parent_id = '" . $_GET['cPath'] . "'
order by c.parent_id, c.sort_order, cd.categories_name";
$data = mysql_query($query);
$rows = 0;
while ($record = mysql_fetch_array($data) ) {
$rows++;
$records[] = $record;
}
$results = '';
$results .= '<?xml version="1.0"?>';
$results .= '<nodes>';
//this is where i need to do a switch, if no results then skip the foreach and put a single row.
foreach ($records as $id=>$row) {
$results .= '<node id="' . $row['categories_id'] . '" text="' . $row['categories_name'] . '" load="cache/' . $row['categories_id'] . '.xml"></node>';
}
$results .= '<node id="1" text="non expanding category"></node>';
$results .= '</nodes>';
$OUTPUT = $results;
$file = 'cache/' . $_GET['cPath'] . '.xml';
$fp = fopen($file,"w");
fputs($fp, $OUTPUT);
fclose($fp);