www.mutationevent.com

Archive pour la catégorie ‘php’

AjaxCRUD

Vendredi 6 mars 2009

AjaxCRUD est une API PHP open-source qui permet de se connecter à une base de données mySQL et facilement effectuer les opérations CRUD (créer, lire, mettre à jour et supprimer ) (create, read, update, & delete rows).

ajaxcrud

Valider l’extension d’un fichier en PHP

Jeudi 3 avril 2008
  1. function validate_extension($file_name) {
  2.  
  3. $ext_array = array(".zip",".rar",".jpg",".jpeg",".gif",".bmp");
  4. $extension = strtolower(strrchr($file_name,"."));
  5. $ext_count = count($ext_array);
  6.  
  7. if (!$file_name) {
  8. return false;
  9. } else {
  10. if (!$ext_array) {
  11. return true;
  12. } else {
  13. foreach ($ext_array as $value) {
  14. $first_char = substr($value,0,1);
  15. if ($first_char <> ".") {
  16. $extensions[] = ".".strtolower($value);
  17. } else {
  18. $extensions[] = strtolower($value);
  19. }
  20. }
  21.  
  22. foreach ($extensions as $value) {
  23. if ($value == $extension) {
  24. $valid_extension = "TRUE";
  25. }
  26. }
  27.  
  28. if ($valid_extension) {
  29. return true;
  30. } else {
  31. return false;
  32. }
  33. }
  34. }
  35. }

PHP and JSON

Mercredi 19 décembre 2007

Dans ce tutoriel nous allons créer des données et les convertir au format JSON.

avant de commencer nous allons d'abord vérifier si la biblioth

Code Igniter un autre FrameWork php

Lundi 12 février 2007

Code Igniter est Framework php qui integre les possibilités qu'offrent les autres Frameworks(cakePHP, phpMVC, Symfony,...).

codeigniter_logo

Features

  • Model-View-Controller Based System
  • PHP 4 Compatible
  • Extremely Light Weight
  • Full Featured database classes with support for several platforms.
  • Active Record Database Support
  • Form and Data Validation
  • Security and XSS Filtering
  • Session Management
  • Email Sending Class. Supports Attachments, HTML/Text email, multiple protocols (sendmail, SMTP, and Mail) and more.
  • Image Manipulation Library (cropping, resizing, rotating, etc.). Supports GD, ImageMagick, and NetPBM
  • File Uploading Class
  • FTP Class
  • Localization
  • Pagination
  • Data Encryption

afficher les archives de votre blog

Vendredi 19 janvier 2007

Afficher les archives de votre blog sous cette forme

  • Janvier 2007 (10)
  • Décembre 2006 (35)
  • ...

Cela peut parfois sembler compliquer mais non, on peut le faire grâce à une seule requête

Supposons notre table "blog"

CREATE TABLE `blog` (
`id_blog` int(11) NOT NULL AUTO_INCREMENT,
`titre` varchar(150) NOT NULL DEFAULT '',
`texte` longtext NOT NULL,
`date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (`id_blog`)
) TYPE=MyISAM ;

Pour afficher les archives :

SELECT DISTINCT YEAR( date ) AS year, MONTH( date ) AS
month , Count( id_blog ) AS posts, MONTHNAME(date) AS monthname
FROM blog
WHERE date < now( )
AND date != '0000-00-00 00:00:00'
GROUP BY YEAR( date ) , MONTH( date )
ORDER BY date DESC

Les champs que nous aurons sont : year,month,post,monthname

Reste plus qu'a les placer dans l'ordre : monthname year (post) avec le code php.

ET voici le code php

$query = "SELECT DISTINCT YEAR( date ) AS year, MONTH( date ) AS
month , Count( id_blog) AS posts, MONTHNAME(date) as monthname
FROM blog
WHERE date < now( )
AND date != '0000-00-00 00:00:00'
GROUP BY YEAR( date ) , MONTH( date )
ORDER BY date DESC "
$result = mysql_query($query,$connect);
$row = mysql_fetch_assoc($result);
 
do {
echo '<li><a href="/site/archives/'.$row['year'].'/'.$row['month'].'/">'.$row['monthname'].' '.$row['year'].' ('.$row['posts'].')</a></li>';
}while($row = mysql_fetch_assoc($result));



  • Archives

  • Catégories

  • @mutationevent