function getBestPowerForLens($params) { if (isset($params['lensID'])) { $lensID = $params['lensID']; } $refraction = $params['refraction']; //get an array of lens powers $lensPowers = getPowerArrayForLens($lensID); $lensPowerArray = $lensPowers['body']; //get some information about the lens $lensData = getLensData($lensID); $toric = $lensData['body'][0]['toric']; $resultArray = getBestCLPowerForParams($refraction, $lensPowerArray, $toric); return $resultArray; }
function updatePowerListsTable($lensID) { //$mysqli = new mysqli('localhost', 'root', 'root', 'eyedock_data'); $mysqli = new mysqli('mysql.eyedock.com', 'eyedockdatauser', 'kvBS^VQR', 'eyedock_data'); //get the rows from lenses_powers table for this lens (these values are listed in ranges) $powerArray = getPowerArrayForLens($lensID); if ($powerArray['head']['status'] != 1) { return; } //print_r ($powerArray['body']); foreach ($powerArray['body'] as $row) { //create the data to insert into the power_lists table $id = $row['id']; $lensID = $row['lensID']; $variation = $row['variation']; $baseCurve = implode(",", $row['baseCurve']); $diameter = implode(",", $row['diameter']); $sphere = implode(",", $row['sphere']); //not every lens is going to have the following rows if ($row['cylinder'] != "") { $cylinder = implode(",", $row['cylinder']); } if ($row['axis'] != "") { $axis = implode(",", $row['axis']); } if ($row['addPwr'] != "") { $addPwr = implode(",", $row['addPwr']); } if ($row['colors_enh'] != "") { $colors_enh = implode(",", $row['colors_enh']); } if ($row['colors_opq'] != "") { $colors_opq = implode(",", $row['colors_opq']); } //check to see if the rows already exist in the power_lists table $sql = "SELECT 1 FROM pn_lenses_power_lists WHERE id =" . $row['id']; $result = $mysqli->query($sql); $count = $result->num_rows; //echo "<p>sql: " . $sql . "</p>"; //echo "<p>count: " . $count . "</p>"; if ($count < 1) { $insertSQL = "INSERT INTO pn_lenses_power_lists (id, lensID, variation, baseCurve, diameter, sphere,cylinder, axis, addPwr, colors_enh, colors_opq)\nVALUES (\n\t\t\n\t\t\t" . $id . " , \n\t\t\t" . $lensID . ",\n\t\t\t'" . variation . "', \n\t\t\t'" . $baseCurve . "', \n\t\t\t'" . $diameter . "', \n\t\t\t'" . $sphere . "', \n\t\t\t'" . $cylinder . "', \n\t\t\t'" . $axis . "', \n\t\t\t'" . $addPwr . "', \n\t\t\t'" . $colors_enh . "', \n\t\t\t'" . $colors_opq . "'\n\t\t)"; } else { //if the row did exist we'll update it $insertSQL = "UPDATE pn_lenses_power_lists SET \n\t\t\tid = " . $id . ", \n\t\t\tlensID = " . $lensID . ", \n\t\t\tvariation = '" . $variation . "', \n\t\t\tbaseCurve = '" . $baseCurve . "', \n\t\t\tdiameter = '" . $diameter . "', \n\t\t\tsphere = '" . $sphere . "',\n\t\t\tcylinder = '" . $cylinder . "', \n\t\t\taxis = '" . $axis . "', \n\t\t\taddPwr = '" . $addPwr . "', \n\t\t\tcolors_enh = '" . $colors_enh . "', \n\t\t\tcolors_opq = '" . $colors_opq . "' \n\t\t\t WHERE id = " . $id . "\n\t\t\t"; } //echo ($insertSQL); $resultarr[] = $mysqli->query($insertSQL); } // go to the next row . . . return $resultarr; }