$cols = array('w.id AS widget_id', 's.id AS service_id', 's.title AS title', 'w.title AS widget', 's.info_title', 's.user_info', 'w.value_title AS widget_info', 'w.value AS widget_value', 'w.description AS description'); $result = $db->join('third_service s', 's.id = w.service_id', 'INNER')->orderBy('s.title', 'ASC')->orderBy('w.title', 'ASC')->where('w.id', $widget_id)->get('third_widget w', null, $cols); } // Everything else if ($service_id) { $cols = array('id AS service_id', 'title', 'user_info', 'info_title', 'description'); $result = $db->where('id', $service_id)->get('third_service', null, $cols); } // Build form if ($db->count > 0) { foreach ($result as $item) { $modal->instructions($item['description']); $modal->input_text("edit[{$item['service_id']}]"); $modal->label("Enter your {$item['info_title']}"); $modal->autofocus(true); $modal->required(true); $modal->value($item['user_info']); $modal->maxlength(32); $modal_output .= $modal->paint(); if ($widget_id) { $modal->input_text('widget_value'); $modal->label("Enter your {$item['widget_info']}"); $modal->required(true); $modal->value($item['widget_value']); $modal->maxlength(32); $modal_output .= $modal->paint(); $modal->headline('Enter your details <span>' . $item['title'] . ' ' . lcfirst($item['widget']) . '</span>'); } else { $modal->headline("Enter your details <span>{$item['title']}</span>"); } }