Creating autocomplete textfields in Drupal6

function ptm_autocomplete_menu() {
 $items['admin/prestum/colors'] = array(
 'title' => 'Colors',
 'description' => 'Colors',
 'page callback' => 'drupal_get_form',
 'page arguments' => array('ptm_colors_form', array(), array()),
 'access arguments' => array('access administration pages'),
 );

$items['admin/prestum/colors/autocomplete'] = array (
 'title' => 'Autocomplete',
 'description' => 'Autocomplete',
 'page callback' => 'ptm_colors_autocomplete',
 'access arguments' => array('access administration pages'),
 'type' => MENU_CALLBACK,
 );

return $items;
}

function ptm_colors_form(&$form_state, $unused, $form_values) {
 $form = array();

$form['name'] = array(
 '#type' => 'textfield',
 '#title' => t('Color'),
 '#description' => t('Color'),
 '#autocomplete_path' => 'admin/prestum/colors/autocomplete',
 );

$form['submit'] = array(
 '#type' => 'submit',
 '#value' => 'Submit',
 );

return $form;
}

function ptm_colors_autocomplete($input) {
 $items = array();

$query = "SELECT color FROM test WHERE color LIKE '%s%%'";

$result = db_query($query, $input);

while ($row = db_fetch_object($result)) {
 $items[$row->color] = $row->color;
 }

print drupal_to_js($items);

exit;
}

Categories: Uncategorized

PHPUnit in netbeans

Excellent tutorial that explains how to set up and use PHPUnit in netbeans.

PHPUnit is a unit testing software framework for PHP

Categories: PHP Tags: , ,

Naming conventions for mysql

Here are the naming conventions I use for mysql.

  • Table names.
    • They must start with the first letter in lowercase.
    • If it’s a multiple-word, separete the words with lowercase.
    • They must be in plural.
  • Field names.
    • Same as table names, but they are in singular.
  • Join tables.
    • table1_table2
  • Primary keys:
    • table_name_id
  • Foreign keys:
    • table_name_table_name_id
Categories: Database Tags: ,

Another Symfony2 presentation

Symfony2 presentation in spanish.

Categories: Symfony Tags: ,

Visual Database Creation with MySQL Workbench

MySQL Workbench is a visual database design tool that integrates SQL development, administration, database design, creation and maintenance into a single integrated development environment for the MySQL database system.

If you want to create entity-relationship diagrams, this is a great program to do it.

You can check this excellent tutorial from nettuts+ in order to learn how to use it.

Categories: Database Tags: , ,

Difference between identifying and non-identifying relationships

An identifying relationship is when the existence of a row in a child table depends on a row in a parent table. This may be confusing because it’s common practice these days to create a pseudokey for a child table, but not make the foreign key to the parent part of the child’s primary key. Formally, the “right” way to do this is to make the foreign key part of the child’s primary key. But the logical relationship is that the child cannot exist without the parent.

Example: A Person has one or more phone numbers. If they had just one phone number, we could simply store it in a column of Person. Since we want to support multiple phone numbers, we make a second table PhoneNumbers, whose primary key includes the person_id referencing thePerson table.

We may think of the phone number(s) as belonging to a person, even though they are modeled as attributes of a separate table. This is a strong clue that this is an identifying relationship (even if we don’t literally include person_id in the primary key of PhoneNumbers).

non-identifying relationship is when the primary key attributes of the parent must not become primary key attributes of the child. A good example of this is a lookup table, such as a foreign key onPerson.state referencing the primary key of States.statePerson is a child table with respect to States. But a row in Person is not identified by its state attribute. I.e. state is not part of the primary key of Person.

A non-identifying relationship can be optional or mandatory, which means the foreign key column allows NULL or disallows NULL, respectively.

Source

Interesting presentations about PHP

Categories: PHP

Semantic Versioning Specification

A normal version number MUST take the form X.Y.Z where X, Y, and Z are integers. X is the major version, Y is the minor version, and Z is the patch version.

Manifesto

Categories: Applications Tags: ,

Always on top

I find this utility very useful in order to set a program’s window always visible when I’m working. For example while I’m using netbeans and I want to check out some code snippet or follow some tutorial in the browser.

You can get it here

Symfony2 presentation in Spanish

You can see it here

Categories: Symfony Tags: ,