Welcome Guest, Not a member yet? Register   Sign In
Database custom sql select statement
#1

[eluser]mypmyp[/eluser]
Hello guys,

I'm completely newbie in CI and I'm confused a bit how can I complete a simple sql query:

SELECT title FROM titles WHERE DIFFERENCE(title, @my_search_param) > 2;

I have tried following:

$query = $this->db->get_where("titles", "title DIFFERENCE(title, '$q') > 2");

I have a feeling that there are no DIFFERENCE function in mysql...

Could you please advise, is there are any alternative in mysql for DIFFERENCE?
PS. I have found that SOUNDEX function is present, but simple comparison for 2 SOUNDEX expressions doesn't work for me.. (I have tried to compare SOUNDEX results, but query selected nothing:
$query = $this->db->get_where("titles", "SOUNDEX(title) = SOUNDEX('$q')");
)

Best regards,
mypmyp Smile
#2

[eluser]Derek Allard[/eluser]
Code:
$this->db->query();

Running Queries.

Welcome to CI mypmyp.

(not familiar with "difference" sorry, but at any rate that's a mysql thing, there's nothing that codeigniter does that will prevent you from doing it.)
#3

[eluser]danmontgomery[/eluser]
You're going to have to tell CI not to escape that statement.

Code:
$query = $this->db->where("SOUNDEX(`title`) = SOUNDEX('$q')", NULL, FALSE)->get("titles");

You can always enable the profiler to see exactly what queries are being run (and therefore how they are being interpreted by AR):

Code:
$this->output->enable_profiler();
#4

[eluser]mypmyp[/eluser]
Hello guys,

Thank you for replies! Smile

Due to the known issues with SOUNDEX, for example 'Brighton' and 'Bristol' will have same phenoms,
I decided to use php similar_text() function, because of it has possibility to tune algorithm sensitivity with alikeness percentage. (http://php.net/manual/en/function.similar-text.php)
This function finds typos like: tpancfopmepc (SOUNDEX: 'T152') for transformers(SOUNDEX: 'T652')! Smile
MS SQL DIFFERENCE will compute value 1 for this example (max is 4). similar_text percentage will be > 40%
So, SOUNDEX not a cool approach for a such issue, levenshtein also is far from a good results.

Since portal has not a lot of products I can allow myself to do a little sin and select ALL products from the database and process'em in the foreach :-D Do not tell anybody Smile

I have found that if I add a field into the database, exactly into this table, I will have ability to fill it with comma separated metaphrases.

Could you please advise:
1. how can I access the database and modify it? (phpmyadmin, ssh, admin page... etc)
2. Is it possible to modify database from the administration area?
3. Is it safe to modify database (add 1 varchar field)?

Such field would be super cool, because I will be able to use REGEXP expression in the query to select possibly alike products.

Thanks in advance.

Best regards,
mypmyp




Theme © iAndrew 2016 - Forum software by © MyBB