-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_blocks.php
41 lines (28 loc) · 923 Bytes
/
get_blocks.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
<?
/* connect to mysql */
$link = mysql_connect('localhost', 'username', 'password') or die('DB Connection failed');
mysql_select_db('database');
/* you could customize this function to get blocks for a specific page or something */
function getBlocks() {
/* get blocks and order by columns */
$blocks = mysql_query("SELECT * FROM blocks ORDER BY order_id ASC");
$columns = array();
while($block = mysql_fetch_array($blocks, MYSQL_ASSOC))
{
$columns[$block['column_id']][] = $block;
}
/* create settings array in javascript style */
$settings = array();
$block_data = array();
foreach ($columns as $column_name => $blocks)
{
$block_to_settings = array();
foreach ($blocks as $block)
{
$block_to_settings[] = '\''.$block['block_id'].'\'';
}
$settings[] = '\''.$column_name.'\'' . ':[' . implode(',', $block_to_settings).']';
}
return implode(',', $settings);
}
?>