[eluser]italoc[/eluser]
i have created a custom variable like this under, and work fine but now i want to replace the tradition SQL syntax with codeigniter syntax , if i write something like this:
Code:
$this->db->select('TB_TEMPLATES.type, TB_USER_PAGES.title, TB_USER_PAGES.title,
TB_USER_PAGES.template_id, TB_USER_PAGES.id');
$this->db->from('TB_USER_PAGES');
$this->db->join('TB_USER_SITES', 'TB_USER_SITES.id = TB_USER_PAGES.site_id');
$this->db->join('TB_TEMPLATES', 'TB_TEMPLATES.id = TB_USER_PAGES.template_id');
$this->db->join('TB_POI_DEFINITION', 'TB_POI_DEFINITION.VALUE = TB_USER_SITES.id');
$this->db->where('TB_POI_DEFINITION.ID', $poi_id);
$query = $this->db->get();
i obtain an error that $db variable is not present...
database library is autoloading. please can you help me??
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Customfunction {
function insertFullText($poi_id, $user_id) {
require 'system/application/views/global_variable.php';
$db_host = 'localhost';
$db_user = 'seety';
$db_password = 'magianlu';
$db_name = 'pois';
$db = mysql_connect($db_host, $db_user, $db_password);
if ($db == FALSE)
die ("Errore nella connessione. Verificare i parametri nel file config.inc.php");
mysql_select_db($db_name, $db)
or die ("Errore nella selezione del database. Verificare i parametri nel file config.inc.php");
$query = "SELECT TB_TEMPLATES.type, TB_USER_PAGES.title, TB_USER_PAGES.template_id, TB_USER_PAGES.id FROM TB_USER_PAGES, TB_USER_SITES, TB_TEMPLATES, TB_POI_DEFINITION WHERE TB_POI_DEFINITION.ID = '".$poi_id."' AND TB_USER_SITES.id = TB_USER_PAGES.site_id AND TB_TEMPLATES.id = TB_USER_PAGES.template_id AND TB_POI_DEFINITION.VALUE = TB_USER_SITES.id";
$result = mysql_query($query, $db);
$fulltext = "";
$title = "";
while ($row = mysql_fetch_array($result)) {
if ($row['type'] == 'wysiwyg' OR $row['type'] == 'galleria') {
$path = $application_path.'framework/uc/'.$user_id.'/'.$row['id'].'/index.html';
$html = file_get_contents($path);
$replace = array(" ");
$html = trim(str_replace($replace,'', strip_tags($html)));
$fulltext = $fulltext.trim($html);
} else {
$query_template = "SELECT var_value FROM `TB_PAGE_VAR_VALUES` WHERE TB_PAGE_VAR_VALUES.pages_id = '".$row['id']."' AND TB_PAGE_VAR_VALUES.var_name like 'text_%'";
$result_template = mysql_query($query_template, $db);
if (mysql_num_rows($result_template)> 0 ){
$html = mysql_result($result_template,0,'var_value');
}
$replace = array(" ");
$html = trim(str_replace($replace,'', strip_tags($html)));
$fulltext = $fulltext.trim($html);
}
$title = $title.trim($row['title'])." ";
};
$query = "UPDATE TB_FULLTEXT SET TB_FULLTEXT.page_text = '$fulltext', TB_FULLTEXT.page_title = '$title' WHERE TB_FULLTEXT.poi_id = '".$poi_id."'";
$result = mysql_query($query, $db);
}
}
?>