Skip to content

Instantly share code, notes, and snippets.

View w-mazed's full-sized avatar

Walid Yacine MAZED w-mazed

  • Boumerdès (35), Algeria
View GitHub Profile
@w-mazed
w-mazed / recusive-category-tree.php
Created January 4, 2021 08:42
Create Category tree with PHP and MySQL
<?php
/**
* Creating category Tree using recursion.
*======================================================*/
function fetchCategoryTree($parent = 0, $spacing = '', $user_tree_array = array())
{
$sql = "SELECT `cid`, `name`, `parent` FROM `category` WHERE 1 AND `parent` = $parent ORDER BY cid ASC";
$query = mysql_query($sql);
@w-mazed
w-mazed / pagnation-limited-links.php
Last active January 2, 2021 12:20
PHP: Function to generate a limited number of pagination links
@w-mazed
w-mazed / display-months.sql
Created November 26, 2019 20:42
SQL: display months between two dates
/**
* List months between two dates, the example display months of current year up to now
*/
SELECT DATE_FORMAT(m1, '%M %Y') AS `date`
FROM (
SELECT ('2019-09-01' - INTERVAL DAYOFMONTH('2019-11-01')-1 DAY) + INTERVAL m MONTH AS m1
FROM (
SELECT @rownum:=@rownum+1 AS m FROM
(SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4) t1,
(SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4) t2,
@w-mazed
w-mazed / display-days.sql
Last active November 26, 2019 20:44
SQL: display days between two dates
/**
* List days between two dates, the example display days of current month up to now
*/
SELECT `date`
FROM (
SELECT adddate('1970-01-01', t4*10000 + t3*1000 + t2*100 + t1*10 + t0) `date`
FROM (
SELECT 0 t0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9
) t0, (
SELECT 0 t1 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9