annotate models/home.php @ 47:886f43b26ee2 extractapp

move/remove develop folder
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Tue, 17 Mar 2015 10:54:13 +0100
parents
children 840cdb52f476
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1 <?php
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
2
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
3 class HomeModel {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
4 public function Index() {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
5 return array("Index Value 1", "Value 2", "Value 3");
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
6 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
7
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
8 public function Test() {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
9
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
10 /* uncomment to do the merge
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
11 // merge books table with books_info table
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
12 $query = "SELECT books_info.volume, books_info.author, books_info.edition, books_info.books_id FROM books INNER JOIN books_info ON books.id=books_info.books_id";
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
13
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
14 $result = mysql_query($query);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
15 if (!$result) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
16 return json_encode("Failed during selecting books, books_info table.");
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
17 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
18 $query = "ALTER TABLE books_v1 ADD Column volume VARCHAR(50), ADD Column author VARCHAR(100), ADD Column edition VARCHAR(100);"
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
19 $result_alter = mysql_query($query);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
20
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
21 while ($row = mysql_fetch_assoc($result)) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
22 // insert row into books_v1 table
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
23 echo $row['volume'].$row['author'].$row['edition'].$row['books_id'];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
24
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
25 $query_update = "UPDATE books_v1 SET `volume`='".$row['volume']."', `author`='".$row['author']."',`edition`='".$row['edition']."' WHERE `id`='".$row['books_id']."'";
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
26
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
27 $result_update= mysql_query($query_update);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
28 if (!$result_update) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
29 echo json_encode("error");
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
30
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
31 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
32 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
33 */
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
34 return;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
35 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
36
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
37 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
38
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
39
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
40
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
41 ?>