Currently, I am working on a project I've "inherited" from someone else and have trouble fixing some stuff.
Just when I thought I am done with this project, I found, that if I search for example "apple" and the suggestions of the search are "foo apple bar", it will throw out "apple foo bar"
Here is the code:
function select_data()
{
global $wpdb;
$product_name=$_POST['product_name'];
if(!empty($product_name))
{
$unique_id = 'prodct_search';
$query ="SELECT * FROM `wp_posts` WHERE `post_title` LIKE '%".$product_name."%' AND `post_type` = 'product'";
$locar = $wpdb->get_results($query);
if($locar)
{
echo '<ul>';
foreach($locar as $loca)
{
echo '<li id="'.$loca->ID.'" onClick="filladsearch_loc('.this.',\''.addslashes($loca->post_title).'\',\''.$unique_id.'\')">'.$loca->post_title.'</li>';
}
echo '</ul>';
}
else
{
echo '<ul><li>No products were found matching your search.</li></ul>';
}
}
die();
}
And
function select_data1()
{
global $wpdb;
$product_name=$_POST['product_name'];
if(!empty($product_name))
{
$unique_id = 'prodct_search';
$query ="SELECT * FROM `wp_posts` WHERE `post_title` LIKE '%".$product_name."%' AND `post_type` = 'product'";
$locar = $wpdb->get_results($query);
if($locar)
{
echo '<ul>';
foreach($locar as $loca)
{
$titcapital=strtoupper($loca->post_title);
$proupper=strtoupper($product_name);
$stringsearched=str_replace($proupper,"",$titcapital);
//$createdarr=explode($product_name,$loca->post_title);
$finalstring='<span class="pro_top">'.strtoupper($product_name).'</span>'.strtoupper($stringsearched);
//print_r($createdarr);
echo '<li id="'.$loca->ID.'" onClick="filladsearch_loc('.this.',\''.addslashes($titcapital).'\',\''.$unique_id.'\')">'.$finalstring.'</li>';
}
echo '</ul>';
}
else
{
echo '<ul><li>No products were found matching your search.</li></ul>';
}
}
die();
}
And here is what it looks like:
Related
I use this code:
$usuario=getJoomUser();
$username=strtolower($usuario['username']);
$name=$usuario['name'];
if ($usuario['id']== 0)
{
echo "$name";
print "No estas logueado en el sistema";
}
else
{
The code works fine but not with some computers. Joomla load fine the user and his password but not my code in PHP. However, if I use that information in other computers works fine.
Any ideas?
Thanks a lot.
My function is:
function getJoomUser() {
error_reporting(1);
define( '_JEXEC', 1 );
define( 'DS', '/' );
define( 'JPATH_BASE', $_SERVER[ 'DOCUMENT_ROOT' ] . DS . 'Joomla3.2.3' );
if(is_file(JPATH_BASE .DS.'configuration.php')) {
require_once(JPATH_BASE .DS.'configuration.php');
} else {
echo "Could not locate configuration.php <br />";
}
if(is_file(JPATH_BASE .DS.'includes/defines.php')) {
require_once(JPATH_BASE .DS.'includes'.DS.'defines.php');
} else {
echo "Could not locate defines.php <br />";
}
if(is_file(JPATH_BASE .DS.'includes/framework.php')) {
require_once(JPATH_BASE .DS.'includes'.DS.'framework.php');
} else {
echo "Could not locate framework.php<br />";
}
if(is_file(JPATH_BASE .DS.'libraries/joomla/factory.php')) {
require_once(JPATH_BASE .DS.'libraries/joomla/factory.php');
} else {
echo "Could not locate factory.php<br />";
}
$mainframe = JFactory::getApplication('site');
$user = JFactory::getUser();
$userData['username'] = $user->username;
$userData['name'] = $user->name;
$userData['id'] = $user->id;
$userData['email'] = $user->email;
$userData['groups'] = $user->groups;
return $userData;
}
?>
I have tried with the option -->guest and the problem continues. The key is: That happens in some pcs and I try to sign in with these user's data in my computer or another computer works fine.
I tried without to call a function and remains the same.
I don't know where you got getJoomUser from but to get the user object, you need to use this:
$user = JFactory::getUser();
You can then do what you wish like so:
if ($user['id'] == 0){
print "No estas logueado en el sistema";
}
else{
echo $user->username;
}
I have update to 3.3.6 and the problem continues.
On Internet Explorer, activating compatibility view works fine. WRONG
I will change to drupal...
Thanks
I want to check the from the controller if I am rendering an add form or just a view. I want to do something like this..
public function clients()
{
try{
if ($_SERVER["REQUEST_URI"] == "/data/clients")
{
$data['client'] = $this->db->query("select * from clients");
$this->load->view('cview/client',$data);
}
else
{
$crud = new grocery_CRUD();
//$crud->set_theme('datatables');
$crud->set_table('clients');
$crud->set_subject('Clients');
crud->required_fields('city');
//$crud->columns('city','country','phone','addressLine1','postalCode');
$output = $crud->render();
$this->load->view('/crud/users',$output);
}
}catch(Exception $e){
show_error($e->getMessage().' --- '. $e->getTraceAsString());
}
}
This would work well except I'm using an Iframe and this doesn't work if the url doesn't change :P
$state = $this->grocery_crud->getState();
this will get the what state it is in.
if (($state == "list" || $state == "success"))
{
$data['client'] = $this->db->query("select * from clients");
$this->load->view('cview/client',$data);
}
else
{
$crud = new grocery_CRUD();
//$crud->set_theme('datatables');
$crud->set_table('clients');
$crud->set_subject('Clients');
$crud->required_fields('city','phone');
//$crud->columns('city','country','phone','addressLine1','postalCode');
$output = $crud->render();
$this->load->view('/crud/users',$output);
}
In this example above "list" will work on cancel button and "success" works on save and update button on the add screen or edit screen.
My model:
function get_data($id)
{
$this->db->select('id, Company, JobTitle');
$this->db->from('client_list');
$this->db->where('id', $id);
$query = $this->db->get();
return $query->result();
}
I want to get the the data from get_data(), is this the right way?
public function show_data( $id )
{
$data = $this->get_data($id);
echo '<tr>';
echo '<td>'.$data['Company'].'</td>';
echo '<td>'.$data['JobTitle'].'</td>';
echo '<td>'.$data['id'].'</td>';
echo '<td></td>';
echo '</tr>';
}
Use the row_array() function to get the data in the array format.
Reference url
http://ellislab.com/codeigniter/user-guide/database/results.html
you can use foreach loop to print
foreach ($data->result() as $row)
{
echo '<tr>';
echo '<td>'.$row['Company'].'</td>';
echo '<td>'.$row['JobTitle'].'</td>';
echo '<td>'.$row['id'].'</td>';
echo '<td></td>';
echo '</tr>';
}
thank you
just to improve answer, I use "general_model" for all my controllers, there are some exceptions where I need special queries, I just create desired model so "general_model" stays same and I can use it in any project.
e.g.
general_model.php
function _getWhere($table = 'table', $select = 'id, name', $where = array()) {
$this->db->select($select);
$q = $this->db->get_where('`'.$table.'`', $where);
return ($q->num_rows() > 0) ? $q->result() : FALSE;
}
.
.
.
//bunch of another functions
in controller I just call
$this->data['books'] = $this->general_model->_getWhere('book', '*', array('active' => '1'));
$this->render('book_list_view'); // $this->load->view('book_list_view', $this->data);
sidenote: I am extending CI_Controller therefore I use $this->data['books'] instead $data['books'] to pass data into view
in view
//check if there are any data
if ($books === FALSE) {
//some error that there are no books yet
} else {
//load data to table or something
foreach ($books as $book) {
$book->id; // book id
}
}
example: i have this file name change log 2013.txt but when its 2014, I want it to create new file name change log 2014.txt
Anyone can help? this is my controller:
<?php
class changelog extends Controller {
function changelog()
{
parent::Controller();
$this->load->helper('form');
}
function index()
{
$this->change_log_add();
}
function change_log_view()
{
$data['message'] = read_file('C:\wamp\www\changeLog\change log 2013.txt');
$this->load->view('change_log_view', $data);
}
function change_log_add()
{
$this->session->set_flashdata('msg','Please Insert the task changed');
$data['action'] = 'changelog/change_log_save_add/';
$this->load->view('change_log_form', $data);
}
function change_log_save_add()
{
if($this->input->post('message') != NULL)
{
date_default_timezone_set ("Asia/Singapore");
$data = date("Y-m-d, H:i:s");
$body = $this->input->post('message');
$text = $data.' - '.$body."\r\n";
if ( ! write_file('C:\wamp\www\changeLog\change log 2013.txt', $text, 'a+'))
{
echo 'Unable to write the file';
}
else
{
$this->session->set_flashdata('msg', 'File Written');
redirect('changelog/change_log_read/');
}
}
}
function change_log_read()
{
if(read_file('C:\wamp\www\changeLog\change log 2013.txt') == NULL)
{
echo 'File is Empty!';
}
else
{
$string = read_file('C:\wamp\www\changeLog\change log 2013.txt');
echo $string;
redirect('changelog/change_log_view/');
}
}
function change_log_update()
{
$this->session->set_flashdata('msg','Please Insert the task changed');
$data['message'] = read_file('C:\wamp\www\changeLog\change log 2013.txt');
$data['action'] = 'changelog/change_log_save_update/';
$this->load->view('change_log_form', $data);
}
function change_log_save_update()
{
if($this->input->post('message') != NULL)
{
$message = $this->input->post('message');
if ( ! write_file('C:\wamp\www\changeLog\change log 2013.txt', $message, 'r+'))
{
echo 'Unable to write the file';
}
else
{
$this->session->set_flashdata('msg', 'File Written');
redirect('changelog/change_log_read/');
}
}
}
}
For each appearance of change log 2013.txt, replace it with :
'change log ' . date('Y') . '.txt'
For example, instead of :
write_file('C:\wamp\www\changeLog\change log 2013.txt', $message, 'r+')
change it to:
write_file('C:\wamp\www\changeLog\change log ' . date('Y') . '.txt', $message, 'r+')
You can change the static 2013 to use php date instead, this should be change in all instance of 2013 over your code
if ( ! write_file('C:\wamp\www\changeLog\changeLog' . date('Y') . '.txt', $message, 'r+'))
Codeigniter will create the file if it doesn't exists
Trying to print out a two tier navigation menu of my categories. For each parent category I would like to print out a list of it's child categories. All the demos I see use Mage::getModel, but trying to get it to work with getChildCategories. Check out the code below, the areas commented out are what is breaking it. Any help would be great.
$nl = chr(10);
$obj = new Mage_Catalog_Block_Navigation();
$main_cats = $obj->getStoreCategories();
echo '<ul>';
foreach ($main_cats as $main) {
// $sub_cats = $this->getChildCategories($main);
$main_class = ($this->isCategoryActive($main)) ? 'current' : '';
echo '<li class="'.$main_class.'">'.$main->getName().''.$nl;
/*
if ($sub_cats->count())) {
echo '<ul>';
foreach ($sub_cats as $sub) {
$sub_class = ($this->isCategoryActive($sub)) ? 'current' : '';
echo '<li class="'.$sub_class.'">'.$sub->getName().'</li>'.$nl;
}
echo '</ul>'.$nl;
}
*/
echo '</li>';
}
echo '</ul>';
What do you think about this?
getting_and_using_categories_and_subcategories