More efficient code for get*sources.php form dropdown lists.

Sun, 11 Jul 2021 15:55:44 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 11 Jul 2021 15:55:44 +0200
changeset 771
9856238e9217
parent 770
dc37f2b0a00b
child 772
f9d266eb0ec6

More efficient code for get*sources.php form dropdown lists.

www/getfermentablesources.php file | annotate | diff | comparison | revisions
www/gethopsources.php file | annotate | diff | comparison | revisions
www/getmiscsources.php file | annotate | diff | comparison | revisions
www/getwatersources.php file | annotate | diff | comparison | revisions
www/getyeastsources.php file | annotate | diff | comparison | revisions
--- a/www/getfermentablesources.php	Mon Jul 05 20:59:10 2021 +0200
+++ b/www/getfermentablesources.php	Sun Jul 11 15:55:44 2021 +0200
@@ -1,7 +1,7 @@
 <?php
 require_once('config.php');
 
-$query = "SELECT * FROM inventory_fermentables ORDER BY supplier,name";
+$query = "SELECT record,name,type,yield,color,add_after_boil,origin,supplier,coarse_fine_diff,moisture,diastatic_power,protein,dissolved_protein,max_in_batch,recommend_mash,graintype,di_ph,acid_to_ph_57,inventory,cost FROM inventory_fermentables ORDER BY supplier,name";
 $connect = mysqli_connect(DBASE_HOST,DBASE_USER,DBASE_PASS,DBASE_NAME);
 if (! $connect) {
 	echo "[]";
@@ -10,28 +10,7 @@
 mysqli_set_charset($connect, "utf8");
 $result = mysqli_query($connect, $query);
 while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
-	$fermentables[] = array(
-		'record' => $row['record'],
-		'name' => $row['name'],
-		'type' => $row['type'],
-		'yield' => $row['yield'],
-		'color' => $row['color'],
-		'add_after_boil' => $row['add_after_boil'],
-		'origin' => $row['origin'],
-		'supplier' => $row['supplier'],
-		'coarse_fine_diff' => $row['coarse_fine_diff'],
-		'moisture' => $row['moisture'],
-		'diastatic_power' => $row['diastatic_power'],
-		'protein' => $row['protein'],
-		'dissolved_protein' => $row['dissolved_protein'],
-		'max_in_batch' => $row['max_in_batch'],
-		'recommend_mash' => $row['recommend_mash'],
-		'graintype' => $row['graintype'],
-		'di_ph' => $row['di_ph'],
-		'acid_to_ph_57' => $row['acid_to_ph_57'],
-		'inventory' => $row['inventory'],
-		'cost' => $row['cost']
-	);
+	$fermentables[] = $row;
 }
 header("Content-type: application/json");
 echo json_encode($fermentables, JSON_UNESCAPED_UNICODE);
--- a/www/gethopsources.php	Mon Jul 05 20:59:10 2021 +0200
+++ b/www/gethopsources.php	Sun Jul 11 15:55:44 2021 +0200
@@ -1,7 +1,7 @@
 <?php
 require_once('config.php');
 
-$query = "SELECT * FROM inventory_hops ORDER BY origin,name";
+$query = "SELECT record,name,alpha,beta,humulene,caryophyllene,cohumulone,myrcene,hsi,total_oil,type,form,origin,inventory,cost FROM inventory_hops ORDER BY origin,name";
 $connect = mysqli_connect(DBASE_HOST,DBASE_USER,DBASE_PASS,DBASE_NAME);
 if (! $connect) {
 	echo "[]";
@@ -10,23 +10,7 @@
 mysqli_set_charset($connect, "utf8" );
 $result = mysqli_query($connect, $query);
 while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
-	$hops[] = array(
-		'record' => $row['record'],
-		'name' => $row['name'],
-		'alpha' => $row['alpha'],
-		'beta' => $row['beta'],
-		'humulene' => $row['humulene'],
-		'caryophyllene' => $row['caryophyllene'],
-		'cohumulone' => $row['cohumulone'],
-		'myrcene' => $row['myrcene'],
-		'hsi' => $row['hsi'],
-		'total_oil' => $row['total_oil'],
-		'type' => $row['type'],
-		'form' => $row['form'],
-		'origin' => $row['origin'],
-		'inventory' => $row['inventory'],
-		'cost' => $row['cost']
-	);
+	$hops[] = $row;
 }
 header("Content-type: application/json");
 echo json_encode($hops);
--- a/www/getmiscsources.php	Mon Jul 05 20:59:10 2021 +0200
+++ b/www/getmiscsources.php	Sun Jul 11 15:55:44 2021 +0200
@@ -1,7 +1,7 @@
 <?php
 require_once('config.php');
 
-$query = "SELECT * FROM inventory_miscs ORDER BY name";
+$query = "SELECT record,name,type,use_use,time,amount_is_weight,inventory,cost FROM inventory_miscs ORDER BY name";
 $connect = mysqli_connect(DBASE_HOST,DBASE_USER,DBASE_PASS,DBASE_NAME);
 if (! $connect) {
 	echo "[]";
@@ -10,16 +10,7 @@
 mysqli_set_charset($connect, "utf8");
 $result = mysqli_query($connect, $query);
 while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
-	$miscs[] = array(
-		'record' => $row['record'],
-		'name' => $row['name'],
-		'type' => $row['type'],
-		'use_use' => $row['use_use'],
-		'time' => $row['time'],
-		'amount_is_weight' => $row['amount_is_weight'],
-		'inventory' => $row['inventory'],
-		'cost' => $row['cost']
-	);
+	$miscs[] = $row;
 }
 header("Content-type: application/json");
 echo json_encode($miscs);
--- a/www/getwatersources.php	Mon Jul 05 20:59:10 2021 +0200
+++ b/www/getwatersources.php	Sun Jul 11 15:55:44 2021 +0200
@@ -1,7 +1,7 @@
 <?php
 require_once('config.php');
 
-$query = "SELECT * FROM inventory_waters ORDER BY name";
+$query = "SELECT record,name,unlimited_stock,calcium,sulfate,chloride,sodium,magnesium,ph,total_alkalinity,inventory,cost FROM inventory_waters ORDER BY name";
 $connect = mysqli_connect(DBASE_HOST,DBASE_USER,DBASE_PASS,DBASE_NAME);
 if (! $connect) {
 	echo "[]";
@@ -10,20 +10,7 @@
 mysqli_set_charset($connect, "utf8");
 $result = mysqli_query($connect, $query);
 while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
-	$waters[] = array(
-		'record' => $row['record'],
-		'name' => $row['name'],
-		'unlimited_stock' => $row['unlimited_stock'],
-		'calcium' => $row['calcium'],
-		'sulfate' => $row['sulfate'],
-		'chloride' => $row['chloride'],
-		'sodium' => $row['sodium'],
-		'magnesium' => $row['magnesium'],
-		'ph' => $row['ph'],
-		'total_alkalinity' => $row['total_alkalinity'],
-		'inventory' => $row['inventory'],
-		'cost' => $row['cost']
-	);
+	$waters[] = $row;
 }
 header("Content-type: application/json");
 echo json_encode($waters);
--- a/www/getyeastsources.php	Mon Jul 05 20:59:10 2021 +0200
+++ b/www/getyeastsources.php	Sun Jul 11 15:55:44 2021 +0200
@@ -1,7 +1,7 @@
 <?php
 require_once('config.php');
 
-$query = "SELECT * FROM inventory_yeasts ORDER BY laboratory,product_id,name";
+$query = "SELECT record,name,type,form,laboratory,product_id,min_temperature,max_temperature,flocculation,attenuation,cells,inventory,cost,tolerance,sta1,bacteria,harvest_top,harvest_time,pitch_temperature,pofpos,zymocide,gr_hl_lo,sg_lo,gr_hl_hi,sg_hi FROM inventory_yeasts ORDER BY laboratory,product_id,name";
 $connect = mysqli_connect(DBASE_HOST,DBASE_USER,DBASE_PASS,DBASE_NAME);
 if (! $connect) {
 	echo "[]";
@@ -10,33 +10,7 @@
 mysqli_set_charset($connect, "utf8");
 $result = mysqli_query($connect, $query);
 while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
-	$yeasts[] = array(
-		'record' => $row['record'],
-		'name' => $row['name'],
-		'type' => $row['type'],
-		'form' => $row['form'],
-		'laboratory' => $row['laboratory'],
-		'product_id' => $row['product_id'],
-		'min_temperature' => $row['min_temperature'],
-		'max_temperature' => $row['max_temperature'],
-		'flocculation' => $row['flocculation'],
-		'attenuation' => $row['attenuation'],
-		'cells' => $row['cells'],
-		'inventory' => $row['inventory'],
-		'cost' => $row['cost'],
-		'tolerance' => $row['tolerance'],
-		'sta1' => $row['sta1'],
-		'bacteria' => $row['bacteria'],
-		'harvest_top' => $row['harvest_top'],
-		'harvest_time' => $row['harvest_time'],
-		'pitch_temperature' => $row['pitch_temperature'],
-		'pofpos' => $row['pofpos'],
-		'zymocide' => $row['zymocide'],
-		'gr_hl_lo' => $row['gr_hl_lo'],
-		'sg_lo' => $row['sg_lo'],
-		'gr_hl_hi' => $row['gr_hl_hi'],
-		'sg_hi' => $row['sg_hi']
-	);
+	$yeasts[] = $row;
 }
 header("Content-type: application/json");
 echo json_encode($yeasts);

mercurial