Osclass forums

Support forums => General help => Topic started by: elizabeth on March 17, 2019, 12:33:30 pm

Title: [SOLVED] Ajax suggestion for categories need some help !
Post by: elizabeth on March 17, 2019, 12:33:30 pm
Hi. After digging in osclass more and more i decided to build my first plugin which is an ajax autocomplete search for categories and subcategories. (wow)

My problem is that i dont know how to call the categories and subcategories in the database so i wil need some basic help.


I really want to make it work and share it here with other users but i m very newby in php and ajax. Hopefully more experienced users could help me.

Waiting for your valuable help
Thank you all.
Title: Re: Ajax suggestion for categories need some help !
Post by: elizabeth on March 17, 2019, 03:26:57 pm
@Patrick @Teseo ?? 
Title: Re: Ajax suggestion for categories need some help !
Post by: patrickFromCroatia on March 17, 2019, 04:49:32 pm
Hello,

Didn't you provide the code? I see the post is edited...

Regards.
Title: Re: Ajax suggestion for categories need some help !
Post by: elizabeth on March 17, 2019, 08:25:40 pm
Hello,

Didn't you provide the code? I see the post is edited...

Regards.

Hi Patrick and thanks for your response. I removed my code because it was pretty much garbage (still newby :) ). However i started again from zero point and since i read the helpers documentation, i have to say that i 'm on good direction now, as i also took a very carefully look to the osclass's database structure and i can now query specific tables for categories and items using 'dao' model.

IMO  Osclass is a very good project and since i started to understand how the code works, i just love it. BTW does anyone knows in what framework is written (if any)?  (Php Symphony, Laravel, Codeigniter  etc)?
Title: Re: Ajax suggestion for categories need some help !
Post by: Web-Media on March 18, 2019, 05:25:31 pm
There is no framework.  It's a stand alone script.
Looks like wordpress as plugin and theme arhitecture.
Looks like codeigniter as database model
Title: Re: Ajax suggestion for categories need some help !
Post by: elizabeth on March 18, 2019, 07:44:22 pm
There is no framework.  It's a stand alone script.
Looks like wordpress as plugin and theme arhitecture.
Looks like codeigniter as database model

Thanks for mentioned it @web-media.
Title: Re: Ajax suggestion for categories need some help !
Post by: elizabeth on March 18, 2019, 07:55:48 pm
Hello,

Didn't you provide the code? I see the post is edited...

Regards.

OK Hi again Patrick. :)

After a lot of tries and hundred lines of code LOL i now have this code that it 50% works.
what i m trying to do now is to create an ajax autocomplete for cities.

Here is my code:

Code: [Select]
if(count($cities)) {
foreach($cities as $city) {
$ctd = $city['pk_i_id'];
$city = City::newInstance()->findByPrimaryKey($ctd);
View::newInstance()->_exportVariableToView('city', City::newInstance()->findByPrimaryKey($ctd));
echo ''.osc_city().'';
}
}

As you can see at the code i m saving the id of the city in a variable called
Code: [Select]
$std .

However the search returns the right number/rows of results (i m limiting them to 5) but every row is empty. As far as i know
Code: [Select]
echo ''.osc_city().''; must return the name of the city but all rows are empty !  with no error logs (thats why i m sure that the database querying works fine) but why in the world i cant get the names of the cities ??? :(

What am i doing wrong ??
Title: Re: Ajax suggestion for categories need some help !
Post by: patrickFromCroatia on March 18, 2019, 10:49:48 pm
Can you turn on SQL debugging and post queries.log to check? Also, try replacing echo ''.osc_city().''; with var_dump(osc_city()): to check if it contains anything (it may be an array).

Just a few notes:
The echo $var function outputs one or more strings. When you only output a variable, you don't need to add quotes: echo osc_city();
The print_r($arr) function prints human-readable information about a variable - used for printing arrays.
The var_dump($var) function dumps information about a variable - prints variable length and type.

Regards.
Title: Re: Ajax suggestion for categories need some help !
Post by: elizabeth on March 19, 2019, 12:16:28 am
Can you turn on SQL debugging and post queries.log to check? Also, try replacing echo ''.osc_city().''; with var_dump(osc_city()): to check if it contains anything (it may be an array).

Just a few notes:
The echo $var function outputs one or more strings. When you only output a variable, you don't need to add quotes: echo osc_city();
The print_r($arr) function prints human-readable information about a variable - used for printing arrays.
The var_dump($var) function dumps information about a variable - prints variable length and type.

Regards.


Thanks for helping Patrick. I replaced  echo ''.osc_city().''; with var_dump(osc_city()); an dnow it returns "NULL". Any idea?
Title: Re: Ajax suggestion for categories need some help !
Post by: patrickFromCroatia on March 19, 2019, 12:56:39 am
Can you try using echo $city['s_name'] to output name, instead of export variable to view etc.?

Regards.
Title: Re: Ajax suggestion for categories need some help !
Post by: elizabeth on March 19, 2019, 09:08:35 am
Thank you Patrick. It worked!!  What can i say ? You are my Hero :)