Forums / Developer / Query the database / Comment49686

Author Topic

Michael Scofield

Monday 09 June 2008 11:15:43 pm

Comment49686

Thank you guys. You were very helpfull to me!

I was able to create the datatype and it's working like a charm now. Very hard work!! :-), but the result pays the price.

I created 3 tables in my database: one for Countries, other for Provinces (states) and other for Cities.

From the object edit template override I'm calling some fetch functions I made available inside a custom module. These fetch functions retrieves the correct countries, provinces and cities from the database.

With countries, when I change the item in the drop-down (html SELECT), I call a Javascript Ajax function that requests a PHP file. Then, the provinces and cities are updated. When I change the item for provinces, an Ajax request returns the new updated list for cities.

I don't know if it's correctly, but to use the database ($db instance), inside the Ajax script, I did the following:

$script =& eZScript::instance( array( 'description' => 'My first test script',
                                     'use-session' => false,
                                     'use-modules' => true,
                                     'use-extensions' => true ) );
$script->initialize();

// gets instance to Exponential DB
$db = eZDB::instance();

..rest of code here...

$script->shutdown();

Without the $script->initialize() the instance for $db wouldn't work.

Btw, Inside the Ajax php script I would like to have used some code to make sure the user is logged in. I tried to find examples in how to do that but after a while I gave up. I concluded that no problem, since the information returned by the Ajax script is not important.

Now I have a new task. In the administration interface I have to create a new administration tab, so I can use it to manage the countries, provinces and cities that are registered in the database.

Anyone have already did that?