Conclusion of a tree in MySQL
The given subject is worn already out up to prograted trunks, but all taki what programmer with it did not collide{face}. I only shall show one example based on base, rekursija with performance of each time of search can appear nenarokom very long, therefore all over again we shall desert all given by one search in a file, and rekursiej we shall be run on it{him}.
It was incurred{carried}.
We shall be defined{determined} with what we shall deal. Provisional tabla will contain at least 3 columns.
CREATE TABLE Tree (
'ID' INT NOT NULL AUTO_INCREMENT,
'ParentID' INT NOT NULL,
'Title' VARCHAR (255) NOT NULL,
PRIMARY KEY ('ID')
)
Well also what to us now to do{make}? It are necessary to write a script which has processed this table and has displayed a tree. As well as it has been said, for the beginning it is necessary to execute search about all base.
SELECT ID, ParentID, Title FROM Tree;
The result is collected as follows. If you imagine a two-dimensional file that without effort will understand the following code.
while ($row = mysql_fetch_assoc ($res)) {
$tree [$row ['ParentID']] [$row ['ID']] = $row ['Title'];
}
To see that lays in a file it is possible to execute simply print_r ($tree) and there will be to you a happiness! For what I have closed up $row ['ID'] on the second level? For communication{connection} with ParentID, we operate tazhe as though we simply carried out searches in rekursii, but we boss files...
function ShowTree ($tree, $pid=0) {
echo " <ul type ='square '> ";
foreach ($tree as $id => $ root) {
if ($pid! = $id) continue;
if (count ($root)) {
foreach ($root as $key => $title) {
echo " <li> {$title} ";
if (count ($tree [$key])) ShowTree ($tree, $key);
}
}
}
echo "</ul>";
}
Step By Step
I probegajus` on all Parent to a tree. If remember that in $root the file with contents of all fields with it ParentID will contain. That it will not be repeated with a conclusion of fields we shall make a plug $pid! = $id for the following call rekursii. It are necessary to be run only on contents for what we start the second foreach. I shall a little be receded. That there were no misunderstanding, type and that the script swears on foreach, is direct before it{him} I do{make} check on quantity{amount} of contents of a file. Naturally, foreach processes a file and besides not "nulevyj"!
We come back.
In the second cycle it is necessary to cause rekursiju for what all over again we shall check up, and whether there are descendants with such parent.
if (count ($tree [$key])) ShowTree ($tree, $key);
Basically that's all. Agree that simply, and time of a script it is saved, give My God. And applications a heap. So consider that if you have read and first time I press hands has penetrated and itself I dump up to the house.
Data exchange between Excel and MySQL
Hardly we shall open a secret if we shall say, that MySQL is for today of one of the most accessible relational SUBD. She is free-of-charge, stable in job and to all other differs quite good speed. Not casually this control system of databases uses huge popularity at developers of the webs - applications constructed on the basis of client-server technology.
Certainly, time never passes for nothing, including for MySQL. EHvoljucionirovav up to 5j versions, she has considerably grown up and has got functions absent earlier (support of the triggers, the enclosed searches, etc.), but... "?" Zhigulis " too four wheels, headlights, a rudder and other attributes, but it not Mercedes. The same way and MySQL is not Oracle ", - the familiar programmer, trying to explain has quoted to me a difference between existing platforms for a data storage. The thoughtful statement, you will say nothing. Good, doloj philosophy, we shall be engaged in business, namely - data exchange in a sheaf " Microsoft Excel - MySQL ".
To experienced programmers of databases for certain on a teeth this operation, but we shall facilitate the uchast` by means of a special superstructure to tabulared editor Excel with dlinnjuhhim name Excel to MySQL Import, Export and Convert 1.1 from company Sobolsoft. The size of the utility - 5,7 Mb, cost - 20 US dollars.
Installation of the application passes without noise and a dust, the only thing, it is necessary to lower a level of safety Excel (Service-> Makros-> Safety), having allowed{resolved} him to carry out makrosy.
Before the beginning of job it is necessary to connect a database by means of special master Setup MySQL Database Connection and to establish connection. And further all like clockwork: at desire it is possible to export the chosen cells to table MySQL, or, on the contrary, to import the necessary information from a database. Naturally, even minimal knowledge of bases of language of structured searches SQL here to not do without, but it is not terrible - in fact documentation navalom.
That up to this scope utilitki from Sobolsoft she is truly many-sided, starting{beginning} from use as the convenient tool for operators of databases and finishing{stopping} operation in own program development. This optimistic note also we shall finish in our small note.

|