-
Notifications
You must be signed in to change notification settings - Fork 0
/
save.php
71 lines (54 loc) · 1.86 KB
/
save.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
63
64
65
66
67
68
69
70
71
<?
/*
--
-- Table structure for table `blocks`
--
CREATE TABLE `blocks` (
`unique_id` int(11) NOT NULL auto_increment,
`block_id` varchar(255) NOT NULL default '',
`column_id` varchar(255) NOT NULL default '',
`order_id` int(11) NOT NULL default '0',
PRIMARY KEY (`unique_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ;
--
-- Dumping data for table `blocks`
--
INSERT INTO `blocks` VALUES(1, 'block-1', 'column-1', 0);
INSERT INTO `blocks` VALUES(2, 'block-3', 'column-2', 0);
INSERT INTO `blocks` VALUES(3, 'block-2', 'column-3', 0);
INSERT INTO `blocks` VALUES(4, 'block-4', 'column-2', 1);
*/
/* connect to mysql */
$link = mysql_connect('localhost', 'username', 'password') or die('DB Connection failed');
mysql_select_db('database');
$data = $_POST;
foreach ($data as $row)
{
/* split up in segments */
$segments = explode(':', $row);
/* define the column */
$column_id = $segments[0];
/* the blocks */
$blocks = explode(',', $segments[1]);
/* we take each block */
foreach ($blocks as $order_id => $block_id)
{
/* check if the block is already present in the database */
$block_exists = mysql_fetch_row(mysql_query("SELECT * FROM blocks WHERE block_id = '{$block_id}'"));
/* if not, we insert it */
if ($block_exists == FALSE)
{
if (empty($block_id)) return;
//mysql_query("INSERT INTO blocks (block_id, column_id, order_id) VALUES ('{$block_id}', '{$column_id}', {$order_id})");
echo "Moved block: {$block_id} to column: {$column_id} and updated rank to: {$order_id}<br />";
}
/* or else we update it */
else
{
if (empty($block_id)) return;
//mysql_query("UPDATE blocks SET block_id = '{$block_id}', column_id = '{$column_id}', order_id = {$order_id} WHERE unique_id = ".$block_exists[0]);
echo "Moved block: {$block_id} to column: {$column_id} and updated rank to: {$order_id}<br />";
}
}
}
?>