ajax autocomplete method

2010-11-26 Thread marvelade
Hi All,

I'm making a search form for our document library at work.

Document HABTM keyword.


In the search form I'd like an autocomplete AJAX input field to find a
registered keyword.

I followed this tutorial:
http://mrphp.com.au/code/search-forms-cakephp

but it doesn't seem to work (when I starttyping words into the input
field there'sno auto-completion). In my case the keywords are in a
separate table, and coupled by a HABTM assoiation, maybe that's the
problem?

In which controller do I put the autoComplete() method? In the
documents_controller or the keywords_controller?


Best regards
G

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: tree structure problem

2010-09-25 Thread marvelade
Fixed it. I first thought it was a database driver issue, so I made a
version that can work with PDO as well as with MySQL, depending on
what database connection u use in dbconnect.inc.php. I timed the
results with microtime() before and after the function call and for a
tree with 755 nodes to an extent of maximum 5 levels it took PDO about
0.73 seconds to echo all the SQL queries to the browser, whereas MySQL
takes 1.22 seconds for the exact same operation
(P.S.: I don't mean this thread to change into an off-topic PDO vs.
MySQL bash. Just sayin'):

Here's the code (you can make your own dbconnect.inc.php file ;) )

 prepare($sql);
$stmt -> execute();
while ($row = $stmt -> fetch(PDO::FETCH_ASSOC))
{
   $right = rebuild_tree($row['id'], $right,$dbtype);
}

break;

default:

echo 'wtf?';

break;
}


echo('UPDATE keywords SET lft='.$left.', rght='. $right.' WHERE id="'.
$parent_id.'";' . "\n");

return $right+1;
}

// call the function or it won't do anything :)

rebuild_tree(0, 1, "PDO"); // replace PDO with MYSQL if that's the
connection you use

?>


You can copy the browser output and paste it into the SQL tab of
PHPMyAdmin. I find this method to be safer because it allows me to see
the queries before they're executed (and possibly see empty fields or
syntax errors before they're committed to the DB)



Best regards,
Marv

On Sep 25, 12:04 am, marvelade  wrote:
> Good news and bad news:
>
> I presumably found a way:
>
> 
> require("./dbconnect.inc.php");
>
> function rebuild_tree($parent_id, $left)
> {
>         global $dbh;
>
>            // the right value of this node is the left value + 1
>            $right = $left+1;
>
>            // get all children of this node
>            $stmt  =  $dbh -> prepare("SELECT id,keyword FROM keywords WHERE
> parent_id='" . $parent . "' AND approved = 1");
>            $stmt -> execute();
>            while ($row = $stmt -> fetch(PDO::FETCH_ASSOC))
>            {
>                $right = rebuild_tree($row['id'], $right);
>            }
>
>            // we've got the left value, and now that we've processed
>            // the children of this node we also know the right value
>            echo('UPDATE categories SET lft='.$left.', rght='.
>                         $right.' WHERE id="'.$parent_id.'";' . "\n");
>
>            // return the right value of this node + 1
>            return $right+1;
>         }
>
> rebuild_tree('0',1);
>
> ?>
>
> Bad news : my server doesn't want to do it due to memory issues:
>
> Fatal error: Out of memory (allocated 5505024) (tried to allocate 40
> bytes) in /customers/nonimportante.es/nonimportante.es/httpd.www/mptt/
> build_lr_query.php on line 14
>
> Any suggestions?
>
> thx + greetz,
> Marv
>
> On Sep 24, 7:45 pm, cricket  wrote:
>
> > On Fri, Sep 24, 2010 at 11:49 AM, marvelade  wrote:
>
> > > I suppose I need to add 'lft' and 'rght' fields to my database but how
> > > do I calculate these values? I never heard of MPTT before and I think
> > > I understand the basics after reading an article about it (http://
> > > articles.sitepoint.com/article/hierarchical-data-database/2), but I
> > > can't really think of an algorythm that would update an existing
> > > database table when only the parent info is available...
>
> > > Any pointers?
>
> > I once tackled that very problem but wasn't successful. I still think
> > it must be possible to write a script to do it but, in the end, I just
> > created a text file and totted through it "by hand". I did search
> > online and, I believe, posted a query to this list, but couldn't find
> > anything.
>
> > > Can I use the CakePHP tree functionality with just the parent_id info
> > > (I'd guess not?) ?
>
> > I'm not sure. I suspect not. It seems to me, though, that MPTT would
> > be the way to go for what you're doing.
>
> > BTW, do check out this 
> > article:http://bakery.cakephp.org/articles/view/tree-helper-1
>
> > It's a little bit confusing but it's definitely useful. I think it'd
> > suit your situation. Let me know if you need some pointers.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: tree structure problem

2010-09-24 Thread marvelade
Good news and bad news:

I presumably found a way:

 prepare("SELECT id,keyword FROM keywords WHERE
parent_id='" . $parent . "' AND approved = 1");
   $stmt -> execute();
   while ($row = $stmt -> fetch(PDO::FETCH_ASSOC))
   {
   $right = rebuild_tree($row['id'], $right);
   }

   // we've got the left value, and now that we've processed
   // the children of this node we also know the right value
   echo('UPDATE categories SET lft='.$left.', rght='.
$right.' WHERE id="'.$parent_id.'";' . "\n");

   // return the right value of this node + 1
   return $right+1;
}

rebuild_tree('0',1);

?>


Bad news : my server doesn't want to do it due to memory issues:

Fatal error: Out of memory (allocated 5505024) (tried to allocate 40
bytes) in /customers/nonimportante.es/nonimportante.es/httpd.www/mptt/
build_lr_query.php on line 14


Any suggestions?


thx + greetz,
Marv




On Sep 24, 7:45 pm, cricket  wrote:
> On Fri, Sep 24, 2010 at 11:49 AM, marvelade  wrote:
>
> > I suppose I need to add 'lft' and 'rght' fields to my database but how
> > do I calculate these values? I never heard of MPTT before and I think
> > I understand the basics after reading an article about it (http://
> > articles.sitepoint.com/article/hierarchical-data-database/2), but I
> > can't really think of an algorythm that would update an existing
> > database table when only the parent info is available...
>
> > Any pointers?
>
> I once tackled that very problem but wasn't successful. I still think
> it must be possible to write a script to do it but, in the end, I just
> created a text file and totted through it "by hand". I did search
> online and, I believe, posted a query to this list, but couldn't find
> anything.
>
> > Can I use the CakePHP tree functionality with just the parent_id info
> > (I'd guess not?) ?
>
> I'm not sure. I suspect not. It seems to me, though, that MPTT would
> be the way to go for what you're doing.
>
> BTW, do check out this 
> article:http://bakery.cakephp.org/articles/view/tree-helper-1
>
> It's a little bit confusing but it's definitely useful. I think it'd
> suit your situation. Let me know if you need some pointers.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: tree structure problem

2010-09-24 Thread marvelade
the more I get to know PHP, the more I need to write recursive
functions... :)

I'll try to come up with something and post my findings.


grtz,
Marv


On Sep 24, 7:45 pm, cricket  wrote:
> On Fri, Sep 24, 2010 at 11:49 AM, marvelade  wrote:
>
> > I suppose I need to add 'lft' and 'rght' fields to my database but how
> > do I calculate these values? I never heard of MPTT before and I think
> > I understand the basics after reading an article about it (http://
> > articles.sitepoint.com/article/hierarchical-data-database/2), but I
> > can't really think of an algorythm that would update an existing
> > database table when only the parent info is available...
>
> > Any pointers?
>
> I once tackled that very problem but wasn't successful. I still think
> it must be possible to write a script to do it but, in the end, I just
> created a text file and totted through it "by hand". I did search
> online and, I believe, posted a query to this list, but couldn't find
> anything.
>
> > Can I use the CakePHP tree functionality with just the parent_id info
> > (I'd guess not?) ?
>
> I'm not sure. I suspect not. It seems to me, though, that MPTT would
> be the way to go for what you're doing.
>
> BTW, do check out this 
> article:http://bakery.cakephp.org/articles/view/tree-helper-1
>
> It's a little bit confusing but it's definitely useful. I think it'd
> suit your situation. Let me know if you need some pointers.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: tree structure problem

2010-09-24 Thread marvelade


I suppose I need to add 'lft' and 'rght' fields to my database but how
do I calculate these values? I never heard of MPTT before and I think
I understand the basics after reading an article about it (http://
articles.sitepoint.com/article/hierarchical-data-database/2), but I
can't really think of an algorythm that would update an existing
database table when only the parent info is available...

Any pointers?

Can I use the CakePHP tree functionality with just the parent_id info
(I'd guess not?) ?


thanks and best regards,
Marv

On Sep 23, 8:02 pm, cricket  wrote:
> On Thu, Sep 23, 2010 at 8:59 AM, marvelade  wrote:
> > Dear all
>
> > For a documentation system we have a tree structure of key words (came
> > from an excel file).
>
> > it's now in a MySQL table with the following columns (field names are
> > pretty self-explanatory)
>
> > CREATE TABLE IF NOT EXISTS `keywords` (
> > `id` smallint(5) unsigned NOT NULL auto_increment,
> > `parent_id` int(10) unsigned default NULL,
> > `keyword` varchar(64) collate utf8_unicode_ci NOT NULL,
> > `approved` tinyint(1) NOT NULL default '0',
> > PRIMARY KEY (`id`)
> > )
>
> > keywords at root level have parent_id NULL.
>
> > I want to have a system so each keyword can display its chain of
> > parents up to the root level
>
> > For example I have this chain:
> > "Nature sciences" -> "chemistry" -> "analysis methods" -> "gas
> > analysis"
>
> > When I view keyword "gas analysis" I want my code to display:
>
> > Parent chain : "Nature sciences" -> "chemistry" -> "analysis methods"
>
> > When I follow the procedure as described here:
> >http://bakery.cakephp.org/articles/view/threaded-lists
>
> > I can't get it to work. I keep getting the error:
>
> > 1064: You have an error in your SQL syntax; check the manual that
> > corresponds to your MySQL server version for the right syntax to use
> > near 'findAllThreaded' at line 1
>
> > For some reason the function name findAllThreaded is passed as a SQL
> > statement :s
>
> > Can anyone please advise? I use CakePHP 1.3
>
> That's because the method no longer exists, so Cake simply passes the
> request directly to the DB. There have been significant changes to the
> Cake libs since that article was posted. Use find('threaded') instead.
> Also, check out TreeBehavior:
>
> http://book.cakephp.org/view/91/Tree

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


tree structure problem

2010-09-23 Thread marvelade
Dear all

For a documentation system we have a tree structure of key words (came
from an excel file).

it's now in a MySQL table with the following columns (field names are
pretty self-explanatory)

CREATE TABLE IF NOT EXISTS `keywords` (
`id` smallint(5) unsigned NOT NULL auto_increment,
`parent_id` int(10) unsigned default NULL,
`keyword` varchar(64) collate utf8_unicode_ci NOT NULL,
`approved` tinyint(1) NOT NULL default '0',
PRIMARY KEY (`id`)
)

keywords at root level have parent_id NULL.



I want to have a system so each keyword can display its chain of
parents up to the root level

For example I have this chain:
"Nature sciences" -> "chemistry" -> "analysis methods" -> "gas
analysis"

When I view keyword "gas analysis" I want my code to display:

Parent chain : "Nature sciences" -> "chemistry" -> "analysis methods"


When I follow the procedure as described here:
http://bakery.cakephp.org/articles/view/threaded-lists

I can't get it to work. I keep getting the error:

1064: You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near 'findAllThreaded' at line 1

For some reason the function name findAllThreaded is passed as a SQL
statement :s


Can anyone please advise? I use CakePHP 1.3

Best regards,
Marvelade

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en