PHP Classes

File: minidoc.txt

Recommend this page to a friend!
  Classes of Pierre FAUQUE   Liste Class   minidoc.txt   Download  
File: minidoc.txt
Role: Documentation
Content type: text/plain
Description: short english documentation
Class: Liste Class
Generate form select inputs from MySQL queries
Author: By
Last change: documentation completed.
Date: 17 years ago
Size: 7,622 bytes


Class file image Download
+---------------------------------------+ | class.liste.php v 1.12 - 06 avr 2006 | | liste: french word, stands for list | | Class used to build combo-lists | | Pierre FAUQUE, | | | +---------------------------------------+ +-----+ +------------+ 0,n / BUY \ 0,n +-----------+ | CLIENTS +-------+---------+-------+ PRODUCTS | +------------+ \ qty / +-----------+ | idclient | +-----+ | idproduct | | first_name | | product | | last_name | | price | +------------+ +-----------+ In that example, we need two definition list files (one for each Merise object) : - clients.def.php - products.def.php clients.def.php : ----------------- <? // clients.def.php $table = "CLIENTS"; $champs = "idclient,last_name,first_name"; $ordre = "last_name,first_name"; $texte = "-- Choose the client --"; ?> products.def.php : ------------------ <? // products.def.php $table = "PRODUCTS"; $champs = "idproduct,product"; $ordre = "product"; $texte = "-- Choose the product --"; ?> NB: The first element of the variable $champs (fields) must be the identifier. That element (identifier) will be wrote in the value attribute: => <option value="14">DOE John (14 is the idclient) To instanciate the clients list and the products list : ------------------------------------------------------- $CLclients = new liste("clients"); // the file which will be read : clients.def.php $CLproducts = new liste("products"); // the file which will be read : products.def.php (NB: Just for me: the variables whose name begins by $CLxxx mean Combo-List) To write the lists : -------------------- $CLclients->write(); $CLproducts->write(); // ================================================================= EXAMPLE: Form script <? require("connexion.php"); // Connexion scripts (provided) require("class.liste.php"); // The class liste itself $CLclients = new liste("clients"); // instanciate the clients list $CLproducts = new liste("products"); // Instanciate the products list ?> <form method="post" action="save.php"> Client : <? $CLclients->write(); ?><br> Product : <? $CLproducts->write(); ?><br> Quantity : <input type="text" size="5" name="qty"><br> <input type="submit" value="Validate"> </form> // ------------------------------------------------------------------ EXAMPLE: Save script <? require("connexion.php"); $request = "insert into BUY (idclient,idproduct,qty) values ('$idclient','$idproduct','$qty'); $result = ExecRequete($request,$connexion); // ExecRequete = function in the connexion script. echo "Purchase stored."; ?> // ================================================================= The names of the lists are the names of the identifiers (=> <select name="idclients">... or <select name="idproduct">...) To give an other name than the identifier, you have to provide a second parameter : $CLclients = new liste("clients","idc"); // => <select name="idc">... $CLproducts = new liste("products","idp"); // => <select name="idp">... or change the attribute 'ctrlname' before writing : $CLclients = new liste("clients"); $CLclients->ctrlname = "idc"; or use the 'changectrlname()' method before writing : $CLclients = new liste("clients"); $CLclients->changectrlname("idc"); --- To use a style in the list, you can provide a third parameter during instanciation. Syntax: $variable = new liste("filedef","ctrlname","style"). The style parameter must be in the third position even the ctrlname is empty ex: $CLclients = new liste("clients","","stcli"); You can also modifiy the 'style' attribute or use the 'usestyle()' method before using the 'write()' method : $CLproducts = new liste("products"); $CLproducts->style = "style12"; or $CLproducts->usestyle("style12"); then: $CLproducts->write(); --- If the list is too large because the text in it is too long, you can cut the text to have : "begin text .../... end text" with a provided width. To do this, you can either modify the 'tronque' attribute or use the 'tronque()' method : $CLproducts = new liste("products"); $CLproducts->tronque = 40; or $CLproducts->tronque(40); then: $CLproducts->write(); --- To display a list with a preselected element, you can indicate the identifier of that element using the 'write()' method : $CLclients->write(37); or $CLclients->write($numclient); --- To display just the text of an element but not that preselected element in a list, use a second parameter (1) in the 'write()' method : $CLclients->write(37,1); or $CLclients->write($numclient,1); --- In the two previous examples the elements are preselected with their identifers. It's possible to preselect an element by a text. ex: towns.def.php contains : $champs = "idcity,town"; $CLtowns->write("London"); or $CLtowns->write("London",1); --- To know the number of elements hold in the list, use the 'nbelements()' method : if($CLclients->nbelements() > 500) { instructions; ... } --- To display the MySQL request (when debugging) use the 'display()' method : $CLclients->display(); --- Others methods of the class : ----------------------------- $CLclients->version(); // version 1.9 du 05 oct 2005. etc... $CLclients->numversion(); // => 1.9 $CLclients->checkversion(); // no new | new version, new features, download link $CLclients->debug(); // show all attributes of the class $CLclients->showdoc(); // french documentation Possible variables in the definition list file : ------------------------------------------------ $table = "table1[,table2]"; // must be there $champs = "idfield,field1[,field2[,field n]]"; // must be there $where = "condition1 [and|or condition2] [and|or condition n]"; // optional $group = "field1[,field2[,field n]]"; // "group by". optional $ordre = "field1[,field2[,field n]]"; // "order by". optional $texte = "Initial text in the list"; // optional $onchange = "javascript function()"; // js function to be executed. optional $lignes = 6; // for a combo with several rows NB: - All information in square brackets [] are optional. - The first field in the '$champs' variable must be the identifier of the Merise object - The provided connexion scripts must be used. The class use the $connexion variable which is defined in these scripts (MySQL link). If you have your own connexion scripts, may be you have to modify the $cnx variable in the constructor and in the 'write()' method of the class. - This class can be stored either in the same directory than the script using it or in the directory designed by 'include_path' in php.ini (this place is better than the other one). You can do any observations at the URL: // to announce a bug // to emit a wish --- Thank you for your attention and your feedback on the website. Pierre FAUQUE, Paris, 2006-04-06