Playing with databases - wild cards

Try online Examples

Here, you will see hot to use an approximate search criteria
The HTML looks like:

	<FORM action="/cgi-bin/aptilis.exe" method="POST">
	<INPUT type="hidden" name="file" value="/home/scripts/db2.e.txt">

	<B>Products Database Search</B>
	<I>By approximation</I><BR>

	<INPUT type="text" name="search" size=20>
	<INPUT type="submit" value="Search...">

	</FORM>

And now, the Aptilis programme...

sub main()

	print("Content-Type: text/html\n\n")

	print("<HTML>\n")
	print("<HEAD>\n<BASE href=\"http://localhost/aptilis/\"></HEAD>\n\n")
	print("<BODY bgcolor=\"#FFFFFF\">\n")

	n = LoadDataBase(db[], "f:/projects/aptilis/documentation/targets/local/scripts/database.txt")
	print(int(n)$," record(s)<BR>\n")

	if n < 1
		print("The database is empty</BODY></HTML>\n")
	return 0
	end if

	// We are going to use a loop to get ALL the matching records.
	n = 0
	x = 0
	repeat

		x = GetRecordIndexByNearKey(db[], search$, 0, x)
		if x != -1

			r = db[x] $

			// Now we output the HTML.
			print("<IMG src=\"gifs/", getfield(r$, 3)$, ".gif\"><BR>\n")
			print("Product: ", getfield(r$,0)$, "<BR>\n")
			print("Prize: &pound;", getfield(r$, 1)$, "<BR>\n")
			print("<HR>\n")
			n = n + 1
			x = x + 1
		end if

	until x = -1

	print("Found: ", int(n)$, " record")
	if n > 1
		// This adds an 's' at the end of records
		// to be grammatically correct in case of plural.
		print("s")
	end if

	print("<BR>\n\n</BODY></HTML>\n")

end main

Things learnt

As a reminder, here is what our test database contains:

"Ferrari","100000","car","testa"
"PC","1000","computer","pc"
"Pizza","5.89","food","pizza"