comparison php/read/updateTierLink.php @ 6:077b0a0a3e6d

remaining originals according to dependency walk
author Robert Boland <robert@markup.co.uk>
date Thu, 16 Feb 2017 22:29:02 +0000
parents
children 385ddd7c4b55 a67bf725e87b
comparison
equal deleted inserted replaced
5:55445b456ad0 6:077b0a0a3e6d
1 <?PHP
2
3 $isbn1 = strval($_GET['isbn1']);
4 echo $isbn1;
5 $isbn2 = strval($_GET['isbn2']);
6 echo $isbn2;
7 $state = strval($_GET['state']);
8 echo $state;
9 if (isset($_GET['userID'])) {
10 $userID=$_GET['userID'];
11 }
12 $loc = strval($_GET['loc']);
13 echo $loc;
14
15 include "../../../private/db.php";
16 //$addState = 0;
17
18 $query1 = "CALL b_getLinkID('$isbn1', '$isbn2', $loc)"; // "select LinkID from scoretable where BookID1 = '$isbn1' and BookID2 = '$isbn2' and LocID = $loc";
19 //echo $query1;
20 $data1 = mysqli_query($link, $query1) or exit( mysqli_error( $link ));
21 mysqli_close($link); //do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop
22 include "../../../private/db.php";
23
24 if ( mysqli_num_rows( $data1 ) < 1 ) //does the link exist
25 {
26 if($state == 7)
27 $queryL = "CALL b_addNewSearchLink('$isbn1','$isbn2',0, $loc)";
28 else
29 $queryL = "CALL b_addNewLink('$isbn1','$isbn2',0, $loc)";
30 //echo $queryL;
31 $results = mysqli_query($link, $queryL);
32
33 $rows=mysqli_fetch_array($results, MYSQLI_ASSOC);
34 $linkid=$rows['LinkID'];
35
36 //reset connection
37 mysqli_close($link); //do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop
38 include "../../../private/db.php";
39
40
41 //if(isset($userID))
42 // $addState = 1;
43 }
44 else
45 {
46 $rows=mysqli_fetch_array($data1, MYSQLI_ASSOC);
47 $linkid=$rows['LinkID'];
48 }
49
50 $query3 = "CALL b_getLinkIDLinks($linkid)"; //"select LinkID, Positive, Buy, StrongInterest, MiddleInterest, WeakInterest, SearchRel, PositiveLogIn, BuyLogIn, StrongInterestLogIn, BuyLogIn, StrongInterestLogIn, MiddleInterestLogIn, WeakInterestLogIn, SearchRelLogIn from links where LinkID = $linkid";
51 //echo $query3;
52 $data = mysqli_query($link, $query3) or exit( mysqli_error( $link ));
53
54 //reset connection
55 mysqli_close($link); //do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop
56 include "../../../private/db.php";
57
58 while($line = mysqli_fetch_assoc($data))
59 {
60 $linkID = $line["LinkID"];
61 $pos = $line["Positive"];
62 $buy = $line["Buy"];
63 $strong = $line["StrongInterest"];
64 $middle = $line["MiddleInterest"];
65 $weak = $line["WeakInterest"];
66 $searchrel = $line["SearchRel"];
67
68 $posLogIn = $line["PositiveLogIn"];
69 $buyLogIn = $line["BuyLogIn"];
70 $strongLogIn = $line["StrongInterestLogIn"];
71 $middleLogIn = $line["MiddleInterestLogIn"];
72 $weakLogIn = $line["WeakInterestLogIn"];
73 $searchrelLogIn = $line["SearchRelLogIn"];
74
75 /*
76 RECOMM = 1;
77 BUY = 2;
78 STRONG = 3;
79 WEAK = 4;
80 CONTEMPLATE = 5;
81 BROWSE = 6;
82 SEARCH = 7;*/
83
84 if(isset($userID))
85 {
86 if($state == 1)
87 $posLogIn += 1;
88 else if($state == 2)
89 $buyLogIn += 1;
90 else if ($state == 3)
91 $strongLogIn += 1;
92 else if ($state == 4)
93 $weakLogIn += 1;
94 else if ($state == 5)
95 $middleLogIn += 1;
96 else if ($state == 7)
97 $searchrelLogIn += 1;
98 }
99 else
100 {
101 if($state == 1)
102 $pos += 1;
103 else if($state == 2)
104 $buy += 1;
105 else if ($state == 3)
106 $strong += 1;
107 else if ($state == 4)
108 $weak += 1;
109 else if ($state == 5)
110 $middle += 1;
111 else if ($state == 7)
112 $searchrel += 1;
113 }
114
115 $updateQuery = "CALL b_increaseTierLink($linkID,$pos,$buy,$strong,$weak,$middle,$searchrel,$posLogIn,$buyLogIn,$strongLogIn,$weakLogIn,$middleLogIn,$searchrelLogIn)";
116 //echo $updateQuery;
117 $dataFinal = mysqli_query($link, $updateQuery);
118
119 if($state == 1)
120 {
121 $stateQuery = "CALL b_insertThumbState($userID,$linkID,1)";
122 //echo $stateQuery;
123 $stateFinal = mysqli_query($link, $stateQuery);
124 }
125 }
126
127 mysqli_close($link);
128
129 ?>