Load a single recipe from the database instead of client side select.

Sat, 08 Dec 2018 15:20:03 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Sat, 08 Dec 2018 15:20:03 +0100
changeset 130
601920b902e5
parent 129
7f41b61c3faf
child 131
71f1ca48c551

Load a single recipe from the database instead of client side select.

www/includes/db_recipes.php file | annotate | diff | comparison | revisions
www/js/rec_edit.js file | annotate | diff | comparison | revisions
--- a/www/includes/db_recipes.php	Sat Dec 08 15:01:23 2018 +0100
+++ b/www/includes/db_recipes.php	Sat Dec 08 15:20:03 2018 +0100
@@ -16,8 +16,6 @@
 $rreplacements = array("\\'");
 $disallowed = array('visibleindex','uniqueid','boundindex','uid');
 
-// get data and store in a json array
-$query = "SELECT * FROM recipes ORDER BY st_guide,st_letter,st_name,name";
 if (isset($_POST['insert']) || isset($_POST['update'])) {
 	if (isset($_POST['insert'])) {
 		// INSERT COMMAND
@@ -164,7 +162,14 @@
 	echo $result;
 
 } else {
-	// SELECT COMMAND
+	/*
+	 * Select all or a given record.
+	 */
+	if (isset($_GET['record'])) {
+		$query = "SELECT * FROM recipes WHERE record='" . $_GET['record'] . "';";
+	} else {
+		$query = "SELECT * FROM recipes ORDER BY st_guide,st_letter,st_name,name";
+	}
 	$result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect));
 	$recipes = '[';
 	$comma = FALSE;
--- a/www/js/rec_edit.js	Sat Dec 08 15:01:23 2018 +0100
+++ b/www/js/rec_edit.js	Sat Dec 08 15:20:03 2018 +0100
@@ -278,7 +278,7 @@
 			{ name: 'mashs', type: 'string' }
 		],
 		id: 'record',
-		url: url
+		url: url + '?record=' + my_record
 	};
 	// Load data and select one record.
 	var dataAdapter = new $.jqx.dataAdapter(source, {
@@ -332,14 +332,7 @@
 		loadError: function (jqXHR, status, error) {
 		},
 		beforeLoadComplete: function (records) {
-			var filteredRecords = [];
 			$('#jqxLoader').jqxLoader('open');
-			for (var i = 0; i < records.length; i++) {
-				if (records[i].record == my_record) {
-					filteredRecords.push(records[i]);
-				}
-			}
-			return filteredRecords;
 		}
 	});
 	dataAdapter.dataBind();

mercurial