Php tag file

Show package versions in Ubuntu

Sometimes the packages are in the ubuntu repositories are not updated in its latest version, to know which is the version of a package we can write the following command:

  packagename apt-cache showpkg 

Now, if you have a small server where we installed packages like apache, mysql and php would be as follows:

Apache:

  apache2-v 

MySQL:

  mysql - version 

PHP

  php - version 

With this information we can see that is installed the version required for various reasons, whether for compatibility, security, etc.

, , , ,

1 Comment

Print a category tree in PHP

When we're creating some kind of CMS is customary to classify content into categories, where they can have children, grandchildren, great-etc.

For example: Our table category has an id, name, father's, where the latter is the id of another category.

planchette

Therefore we can complicate print that list correctly. To resolve this we can make a small function:

 sacarHijos function ($ id_padre, $ level)
 (
     $ Result = mysql_query ("SELECT id, name, parent FROM categories WHERE parent = $ id_padre");

     if (mysql_num_rows ($ result))
     (
	 $ Level = $ level .'-----';
	 while ($ d = mysql_fetch_row ($ result))
	 (
	     / / Print tree categories
	     echo $ level. '>'. $ d [1];

	     / / Call the function again to print other children
	     sacarHijos ($ d [0], $ level);
	 )
     )
 )

Of course when you call the function sacarHijos the value that is passed in the variable $ level may be empty, eg

 / / We tell the function to print the daughters of the father 00 categories, namely the root.
 sacarHijos (00 ,'');

This allows us to print a tree or hierarchy of categories to print in tables, list of menu options, etc.

,

No Comment