[PHP] Return the amount of times a number occurs in an array

This exercise is about creating a function that can return the amount of times a number occurs in an array. $zahlen1 = array(4,4,3,5,6,7,4,4); $zahlen2 = array(1,2,6,6,3,4,5,5,5,6,7,8,6,9); $zahlen = $zahlen2; echo longestrow($zahlen); function longestrow($zahlen){ $amount = 0; $flag = 0; foreach ($zahlen as $value) { foreach ($zahlen as $value2) { if ($value === $value2) { $amount++; if ($amount > $flag) { …

How to calculate the Median in Mysql

Since there are no built in functions to calculate the median value. You need to calculate it yourself. An important thing to know we refer twice to the country table. Once with x and once with y since we need it in our calculation.   set @median_density = (SELECT x.population/x.area from Mondial.country x, Mondial.country y GROUP BY x.population/x.area HAVING SUM(SIGN(1-SIGN(y.population/y.area-x.population/x.area)))/COUNT(*) …

Mondial SQL Database Questions and Answers

You can find the Mondial SQL database here List all the countries that are part of Nato SELECT distinct c.name FROM Mondial.country c left join Mondial.isMember m on c.code = m.country where m.organization like ‘%nato%’; List all countries that are part of and organisation that was founded before 1960 SELECT * FROM Mondial.country c left join Mondial.isMember m on c.code …

PHP: Basic Programming Heap Sort algorithm

Exercise from W3schools Write a PHP program to sort a list of elements using Heap sort. In computer science, heapsort (invented by J. W. J. Williams in 1964) is a comparison-based sorting algorithm. Heapsort can be thought of as an improved selection sort: like that algorithm, it divides its input into a sorted and an unsorted region, and it interactively …

SQL: Bulkinsert data FROM CSV or TXT File

Very useful for bulk inserting data rapidly from multiple files. At the moment with this sequence you will need to change the file manually. Still very useful. Make sure you check that no columns were imported accidentally.   BULK INSERT [Clientdatabase].[dbo].[journalentries] FROM ‘C:\Users\mxk\Desktop\Clientfolder\Rawdata\Clientdata.TXT’ WITH ( fieldterminator = ‘~’, rowterminator = ‘\n’, firstrow = 2, tablock )

SQL Error: Argument data type date is invalid for argument 2 of dateadd function

You new to cast the complete column as an integer before you can use the dateadd function. That means the following code: ,dateadd(d, CONVERT(date, CASE WHEN fda.[Column1] != 0 THEN fda.[Column1] WHEN fda.[Column2] != 0 THEN bfda.[Column1] ELSE fda.[Column3] END ,114), CONVERT(date, fda.[Column3], 114)) AS [tdate] needs to be changed to the code below. Note the convert becomes cast.   …