/
count.php
63 lines (57 loc) · 1.4 KB
/
count.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/**
* @name jmd_count
* @description Count stuff.
* @author Jon-Michael Deldin
* @author_uri http://jmdeldin.com
* @version 0.1.1
* @type 0
* @order 5
*/
/**
* Counts the number of rows in a table.
*
* @param array $atts
* @param string $atts['table'] MySQL table name.
* @param string $atts['where'] MySQL WHERE clause.
*/
function jmd_count($atts)
{
extract(lAtts(array(
'table' => '',
'where' => '',
), $atts));
if ($where != '')
$where = ' where '. $where;
return getThing("select count(*) from ". safe_pfx($table) ." $where");
}
/**
* Evaluate counting results.
*
* @param array $atts
* @property string $atts['eval'] Valid PHP comparison operator.
* @property string $atts['table'] MySQL table name.
* @property string $atts['where'] MySQL WHERE clause.
*/
function jmd_if_count($atts, $thing)
{
extract(lAtts(array(
'eval' => '',
'table' => '',
'where' => '',
), $atts));
global $jmd_count_value;
$jmd_count_value = jmd_count(array('table' => $table, 'where' => $where));
$condition = eval("return($jmd_count_value $eval);");
$out = EvalElse($thing, $condition);
return parse($out);
}
/**
* Returns the total number of rows as set by @see jmd_if_count()
*
* @param array $atts
*/
function jmd_count_value($atts)
{
return $GLOBALS['jmd_count_value'];
}