Mercurial > hg > ywww
annotate php/read/similar.php @ 30:b1bbf44c701b
standarise semaphore use
author | Robert Boland <robert@markup.co.uk> |
---|---|
date | Fri, 04 Jan 2019 08:50:23 -0500 |
parents | d606320ec331 |
children | d9dd9705e724 |
rev | line source |
---|---|
6
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
1 <?php |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
2 |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
3 function dbConnect($go) |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
4 { |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
5 if($go == 1) |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
6 { |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
7 return "../../private/db.php"; |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
8 } |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
9 else |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
10 { |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
11 return "../../../private/db.php"; |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
12 } |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
13 } |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
14 |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
15 function addAmazonSimilarBooks($isbn1, $loc, $go) |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
16 { |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
17 include dbConnect($go); |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
18 |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
19 $queryLoc = "CALL getLocation('$loc')"; //"select locname from location where LocID = $loc"; |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
20 $res = mysqli_query($link, $queryLoc) or exit( mysqli_error( $link )); |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
21 mysqli_close($link); //do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
22 include dbConnect($go); |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
23 |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
24 $rows=mysqli_fetch_array($res, MYSQLI_ASSOC); |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
25 $locale=$rows['locname']; |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
26 |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
27 $Adefault=array( |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
28 'language' =>'en', //what language to render the page in |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
29 'locale' =>$locale, //which server's products? available: ca,de,fr,jp,uk,us |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
30 'page' =>1, |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
31 'operation' =>'SimilarityLookup', |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
32 'searchparameter' =>'ItemId', //what kind of search? |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
33 'searchparameterdata'=>$isbn1, //what to search for? |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
34 ); |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
35 |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
36 |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
37 $Aassociates_id=array( |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
38 'uk' => 'bookwhack-21', |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
39 'us' => 'your02b-20', |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
40 'ca' => 'book009-20', |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
41 'de' => 'book04c-21', |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
42 'fr' => 'book07f-21', |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
43 ); |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
44 |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
45 $Aserver=array( |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
46 'ca' => array( |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
47 'ext' => 'ca' , //Canadian normal server |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
48 'nor' => 'http://www.amazon.ca' , //Canadian normal server |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
49 'xml' => 'http://xml.amazon.com' , //Canadian xml server |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
50 ), |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
51 'de' => array( |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
52 'ext' => 'de' , //German normal server |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
53 'nor' => 'http://www.amazon.de' , //German normal server |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
54 'xml' => 'http://xml-eu.amazon.com', //German xml server |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
55 ), |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
56 'fr' => array( |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
57 'ext' => 'fr' , //French normal server |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
58 'nor' => 'http://www.amazon.fr' , //French normal server |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
59 'xml' => 'http://xml-eu.amazon.com', //French xml server |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
60 ), |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
61 'jp' => array( |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
62 'ext' => 'jp' , //Japanese normal server, not co.jp! |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
63 'nor' => 'http://www.amazon.co.jp' , //Japanese normal server |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
64 'xml' => 'http://xml.amazon.com' , //Japanese xml server |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
65 ), |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
66 'uk' => array( |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
67 'ext' => 'co.uk' , //UK normal server |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
68 'nor' => 'http://www.amazon.co.uk' , //UK normal server |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
69 'xml' => 'http://xml-eu.amazon.com', //UK xml server |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
70 ), |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
71 'us' => array( |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
72 'ext' => 'com' , //USA normal server |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
73 'nor' => 'http://www.amazon.com' , //USA normal server |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
74 'xml' => 'http://xml.amazon.com' , //USA xml server |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
75 ), |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
76 ); |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
77 |
17
ae1459564f66
Replace old associate keys with new IAMs user keys
Robert Boland <robert@markup.co.uk>
parents:
6
diff
changeset
|
78 include "aws_signed_request.php"; |
ae1459564f66
Replace old associate keys with new IAMs user keys
Robert Boland <robert@markup.co.uk>
parents:
6
diff
changeset
|
79 $public_key ="AKIAIHTNWC7L6LOUY4LQ"; |
ae1459564f66
Replace old associate keys with new IAMs user keys
Robert Boland <robert@markup.co.uk>
parents:
6
diff
changeset
|
80 $private_key="zWQlIzndJDtXNfxEXH7K7YR7hzv3u77lOcqfqPde"; |
ae1459564f66
Replace old associate keys with new IAMs user keys
Robert Boland <robert@markup.co.uk>
parents:
6
diff
changeset
|
81 |
6
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
82 |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
83 //for all parameters see if the user has overruled it or use the default |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
84 foreach ($Adefault as $i=>$d) { |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
85 $$i=isset($_GET[$i])?$_GET[$i]:$d; |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
86 } |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
87 |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
88 $parameters=array( |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
89 'Operation' =>$operation , |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
90 //'Keywords' =>urlencode($search) , |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
91 //'SearchIndex' =>$searchindex , //Books for example. |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
92 "$searchparameter"=>$searchparameterdata , |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
93 'ItemPage' =>$page , //which page? |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
94 'AssociateTag' =>$Aassociates_id[$locale], |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
95 'ResponseGroup' =>'Small' , //Small, Medium, Large or SellerListing, Similarities |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
96 'Availability'=>'Available', |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
97 ); |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
98 |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
99 $ext=$Aserver[$locale]['ext']; |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
100 |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
101 $url=aws_signed_request($ext,$parameters,$public_key,$private_key); |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
102 //echo $url; |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
103 |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
104 $crl = curl_init(); |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
105 $timeout = 5; |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
106 curl_setopt ($crl, CURLOPT_URL,$url); |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
107 curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1); |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
108 curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout); |
21
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
17
diff
changeset
|
109 $gotit=0; |
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
17
diff
changeset
|
110 $semaphore = new SyncSemaphore("Amazon"); |
23
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
111 $gotit = $semaphore->lock(1000); |
21
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
17
diff
changeset
|
112 if (!$gotit) { |
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
17
diff
changeset
|
113 file_put_contents('/var/ywww/debug/phpDebug', |
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
17
diff
changeset
|
114 "Got it: ".(int)$gotit." 4\n",FILE_APPEND); |
23
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
115 $gotit = $semaphore->lock(1000); |
21
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
17
diff
changeset
|
116 file_put_contents('/var/ywww/debug/phpDebug', |
23
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
117 "Got it: ".(int)$gotit." 4a\n",FILE_APPEND); |
21
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
17
diff
changeset
|
118 } |
6
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
119 $ret = curl_exec($crl); |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
120 curl_close($crl); |
23
d606320ec331
post-5.7-upgrade efforts to reduce dropped connections, db insertion fails
Charlie Root
parents:
21
diff
changeset
|
121 usleep(500000); |
21
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
17
diff
changeset
|
122 if ($gotit) { |
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
17
diff
changeset
|
123 $semaphore->unlock(); |
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
17
diff
changeset
|
124 } |
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
17
diff
changeset
|
125 else { |
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
17
diff
changeset
|
126 file_put_contents('/var/ywww/debug/phpDebug', |
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
17
diff
changeset
|
127 "Unlocking 4\n",FILE_APPEND); |
46382face560
use a semaphore to try to cut down on RequestThrottled fails
Charlie Root
parents:
17
diff
changeset
|
128 } |
6
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
129 //echo $ret; |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
130 |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
131 $xml = new SimpleXMLElement($ret); |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
132 |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
133 //$isbn1 = $xml->Items->Request->SimilarityLookupRequest->ItemId; |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
134 //echo $isbn1; |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
135 |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
136 $result = ""; |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
137 for($i=0;$i<sizeof($xml->Items->Item);$i++){ |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
138 foreach($xml->Items->Item[$i]->ASIN as $isbn2){ |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
139 // echo $isbn2; |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
140 |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
141 $group = $xml->Items->Item[$i]->ItemAttributes->ProductGroup; |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
142 |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
143 //foreach one of these, create a new request to check whether its a book. |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
144 //if it is then add it to the return (or add it to the database) |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
145 if($group == 'Book') |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
146 { |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
147 $query1 = "CALL b_getLinkID('$isbn1', '$isbn2', $loc)"; // "select ScoreID from scoretable where BookID1 = '$isbn1' and BookID2 = '$isbn2' and LocID = $loc"; |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
148 //echo $query1; |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
149 $data1 = mysqli_query($link, $query1) or exit( mysqli_error( $link )); |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
150 mysqli_close($link); //do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
151 include dbConnect($go); |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
152 |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
153 if ( mysqli_num_rows( $data1 ) < 1 ) |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
154 { |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
155 $queryL = "CALL b_addNewLink('$isbn1','$isbn2',0,$loc)"; |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
156 //echo $queryL; |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
157 $results1 = mysqli_query($link, $queryL); |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
158 |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
159 $rows=mysqli_fetch_array($results1, MYSQLI_ASSOC); |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
160 $linkid=$rows['LinkID']; |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
161 |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
162 //reset connection |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
163 mysqli_close($link); //do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
164 include dbConnect($go); |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
165 |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
166 //$scoreQuery = "CALL b_insertTempScore('$isbn1','$isbn2',$loc,$linkid,0)"; |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
167 //echo $scoreQuery; |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
168 //$scoreFinal = mysqli_query($link, $scoreQuery); |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
169 $result .= "<type>0</type>"; |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
170 $result .= "<isbn>" . $isbn2 . "</isbn>"; |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
171 $result .= "<linkID>" . trim($linkid) . "</linkID>"; |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
172 } |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
173 } |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
174 } |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
175 } |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
176 |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
177 return $result; |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
178 } |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
179 |
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
diff
changeset
|
180 ?> |