i want to select from database by url and for this i do this if:
if (isset($_GET['class']) == 'dw')
{
$query = mssql_query("select * from [WebShop] where [category]='".secure($string)."' and [dw] > 0 order by credits asc");
}
if (isset($_GET['class']) == 'bk')
{
$query = mssql_query("select * from [WebShop] where [category]='".secure($string)."' and [bk] > 0 order by credits asc");
}
if (isset($_GET['class']) == 'fe')
{
$query = mssql_query("select * from [WebShop] where [category]='".secure($string)."' and [fe] > 0 order by credits asc");
}
if (isset($_GET['class']) == 'mf')
{
$query = mssql_query("select * from [WebShop] where [category]='".secure($string)."' and [mf] > 0 order by credits asc");
}
if (isset($_GET['class']) == 'dl')
{
$query = mssql_query("select * from [WebShop] where [category]='".secure($string)."' and [dl] > 0 order by credits asc");
}
if (isset($_GET['class']) == 'sum')
{
$query = mssql_query("select * from [WebShop] where [category]='".secure($string)."' and [sum] > 0 order by credits asc");
}
if (isset($_GET['class']) == 'rf')
{
$query = mssql_query("select * from [WebShop] where [category]='".secure($string)."' and [rf] > 0 order by credits asc");
}
else
{
$query = mssql_query("select * from [WebShop] where [category]='".secure($string)."' order by credits asc");
}
Url for this is: index.php?sy=items&class=dw
but when i access this url index.php?sy=items&class=dw is selected last if :( : index.php?sy=items&class=rf
can help me to resolve for work with each if ?
Here Try to change the format of your code in this pattern...
$class=$_GET['class']
switch($class) {
case 'dw':
$query = mssql_query("select * from [WebShop] where [category]='".secure($string)."' and [dw] > 0 order by credits asc");
break;
case 'bk':
$query = mssql_query("select * from [WebShop] where [category]='".secure($string)."' and [bk] > 0 order by credits asc");
break;
case 'fe':
$query = mssql_query("select * from [WebShop] where [category]='".secure($string)."' and [fe] > 0 order by credits asc");
break;
default:
code to be executed if n is different from all labels;
}
Related
I was looking at some code which came with the following short-hand statement
score = ((initialPlayer == player) ? CAPTURE_SCORE : -CAPTURE_SCORE) + recursive_solver(lastMap, initialPlayer, findOpponent(player), 1 + rounds);
I think that I understand the first portion of the code,
if(initialPlayer == player){
score = CAPTURE_SCORE;
}
else
score = -CAPTURE_SCORE;
but im confused to how the +recursive_solver function is added to this, any help would be greatly appreciated :)
As stated above I tried to write out the statement in a longer from thats easier for me to read. My best guess is that the recursive solver function is then added to the score of the if-else statement?
if(initialPlayer == player)
score = CAPTURE_SCORE + recursive_solver(lastMap, initialPlayer, findOpponent(player), 1 + rounds);
else
score = -CAPTURE_SCORE + recursive_solver(lastMap, initialPlayer, findOpponent(player), 1 + rounds);
Explanation:
A = (C ? B : D) + E;
If C is true: A = (B) + E;
If C is false: A = (D) + E;
In sum
if (C)
A = B + E;
else // if (!C)
A = D + E;
score = ((initialPlayer == player) ? CAPTURE_SCORE : -CAPTURE_SCORE) + recursive_solver(lastMap, initialPlayer, findOpponent(player), 1 + rounds);
Equals to
if(initialPlayer == player) {
score = CAPTURE_SCORE;
} else {
score = -CAPTURE_SCORE;
}
score += recursive_solver(lastMap, initialPlayer, findOpponent(player), 1 + rounds);
How To add where Condition if request parameter exist in Laravel 5.5
Suppose:
$a = $request->name;
$b = $request->id;
$c = $request->option;
$d = $request->type;
$cities = Pocities::where('region_id', $state_id)
->where('is_active', 1)
->pluck('uuid')->toArray();
$tours = Tour::select(['id', 'uuid','city_uuid', 'tour_name', 'tour_image', 'is_top_tour','places', 'created_at'])
->with(['pocity' => function ($query) {
$query->select('id', 'uuid', 'cities_id', 'region_id', 'country_id');
},'pocity.city','pocity.poregion' ,'pocity.pocountry'])
->whereHas('pocity',function ($query) use ($cities) {
$query->whereIn('uuid', $cities);
})->where('is_active');
if($request->name != ''){
$tours->where('name', $request->name);
}
if($request->id != ''){
$tours->where('id', $request->id);
}
if($request->type != ''){
$tours->where('type', $request->type);
}
$tours->paginate(10);
I have tried this every time given
#query: Builder {#1944
+connection: MySqlConnection {#621
#pdo: PDOConnection {#1926
inTransaction: false
attributes: {
CASE: NATURAL
ERRMODE: EXCEPTION
AUTOCOMMIT: 1
PERSISTENT: false
DRIVER_NAME: "mysql"
SERVER_INFO: "Uptime: 980 Threads: 7 Questions: 420 Slow queries: 0 Opens: 24 Flush tables: 1 Open tables: 18 Queries per second avg: 0.428"
ORACLE_NULLS: NATURAL
CLIENT_VERSION: "mysqlnd 5.0.12-dev - 20150407 - $Id: 38fea24f2847fa7519001be390c98ae0acafe387 $"
SERVER_VERSION: "5.5.5-10.2.14-MariaDB"
STATEMENT_CLASS: array:2 [
0 => "Doctrine\DBAL\Driver\PDOStatement"
1 => []
]
EMULATE_PREPARES: 0
CONNECTION_STATUS: "127.0.0.1 via TCP/IP"
DEFAULT_FETCH_MODE: BOTH
}
}
You can do with following if above is not working for you.
$tours = Tour::query();
//Add your conditions here
$tours->->with(['pocity' => function ($query) {
$query->select('id', 'uuid', 'cities_id', 'region_id', 'country_id');
},'pocity.city','pocity.poregion' ,'pocity.pocountry'])
->whereHas('pocity',function ($query) use ($cities) {
$query->whereIn('uuid', $cities);
})->where('is_active')
//Add your conditionally parameters in this way.
if($request->name != ''){
$tours->where('name', $request->name);
}
$tours->paginate(10);
I am assuming that what column names you are passing is correct.
You can you query builder for where clause in laravel5.5
$a = $request->name;
$b = $request->id;
$c = $request->option;
$d = $request->type;
$cities = Pocities::where('region_id', $state_id)
->where('is_active', 1)
->pluck('uuid')->toArray();
$tours = Tour::select(['id', 'uuid','city_uuid', 'tour_name', 'tour_image', 'is_top_tour','places', 'created_at'])
->with(['pocity' => function ($query) {
$query->select('id', 'uuid', 'cities_id', 'region_id', 'country_id');
},'pocity.city','pocity.poregion' ,'pocity.pocountry'])
->whereHas('pocity',function ($query) use ($cities) {
$query->whereIn('uuid', $cities);
})->where('is_active');
if($request->name != '' && $request->id != '' && $request->type != ''){
$tours = Pocities::query();
$tours->where('name', $request->name);
$toursData = $tours->paginate(10);
}
I am trying to make this statement applicable to some cells in my google spreadsheet :
if ((B29 - B36) > 0) {
(B29 - B36) * (D36 / 100) + F35 + F34 + F33
} else if ((B29 - B35) > 0) {
(B29 - B35) * (D35 / 100) + F34 + F33);
} else if (B29 - B34 > 0) {
(B29 - B34) * (D34 / 100) + F33);
} else {
0
}
I tried to make it with only IF, but the cells didn't like the syntax :
=IF((B29 - B36) > 0);((B29 - B36) * (D36 / 100) + F35 + F34 + F33);IF((B29 - B35) > 0);((B29 - B35) * (D35 / 100) + F34 + F33);IF((B29 - B34) > 0);((B29 - B34) * (D34 / 100) + F33);0
How can I achieve this?
correct syntax would be like this:
=IF(B29-B36 > 0; (B29-B36)*(D36/100)+F35+F34+F33;
IF(B29-B35 > 0; (B29-B35)*(D35/100)+F34+F33;
IF(B29-B34 > 0; (B29-B34)*(D34/100)+F33; 0)))
I've created an if statement to control if a customer discount is right. I take the sales volume of its previous year, control if it is in the exact range, then if it is not I need to write the right discount to apply. My problem is that this suggested discount is not the right one. I'll show you the code.
Before I give a sample customer data.
Discount Applied is 60 %
Sales Volume 2016--->€ 13.895.90
Sales Volume 2015 ---> € 25.686.92
This is my query:
DECLARE all variables that i need......
SET #Anno1 = YEAR(GETDATE());
SET #Anno2 = YEAR(DATEADD(year,-1,GETDATE()));
SET #Anno3 = YEAR(DATEADD(year,-2,GETDATE()));
SET #datada = DATEADD(DAY, -15, GETDATE());
SET #dataa = GETDATE();
----- set discount sales volume ---
SET #40 = '€ '+ REPLACE(CONVERT(varchar, CAST('1500.0000' AS money), 105),',','.');
SET #50 = '€ '+ REPLACE(CONVERT(varchar, CAST('15000.0000' AS money), 105),',','.');
SET #60 = '€ '+ REPLACE(CONVERT(varchar, CAST('150000.0000' AS money), 105),',','.');
SET #70 = '€ '+ REPLACE(CONVERT(varchar, CAST('200000.0000' AS money), 105),',','.');
SET #80 = '€ '+ REPLACE(CONVERT(varchar, CAST('500000.0000' AS money), 105),',','.');
---create cursor---
DECLARE c CURSOR FOR
SELECT DISTINCT
CODCONTO,
DSCCONTO1
FROM .dbo.TESTEDOCUMENTI
WHERE D (.dbo.TESTEDOCUMENTI.TIPODOC = 'PCL' OR .dbo.TESTEDOCUMENTI.TIPODOC = 'ORC' ) AND .dbo.TESTEDOCUMENTI.DATADOC BETWEEN #datada AND #dataa
----take each customer----
OPEN c
FETCH NEXT FROM c INTO #CodiceCliente,#Cliente
--IF #CodiceCliente IS NULL goto finescript;
WHILE ##FETCH_STATUS = 0
BEGIN
-------------------------------------------------------------------
----------------------set sales volumes to variables---
-------------------------------Current year -----
SET #FattAnnoCorrente =
(SELECT '€ '+ REPLACE(CONVERT(varchar, CAST(SUM(TOTIMPONIBILE) AS money), 105),',','.') FROM .dbo.TESTEDOCUMENTI
WHERE CODCLIFOR = #CodiceCliente ANDAND .dbo.TESTEDOCUMENTI.TIPODOC = 'FVC' AND .dbo.TESTEDOCUMENTI.ESERCIZIO = YEAR(GETDATE()));
-------------------------------Previous Year -----
SET #FattAnnoPrecedente =
(SELECT '€ '+ REPLACE(CONVERT(varchar, CAST(SUM(TOTIMPONIBILE) AS money), 105),',','.') FROM .dbo.TESTEDOCUMENTI
WHERE CODCLIFOR = #CodiceCliente AND .dbo.TESTEDOCUMENTI.TIPODOC = 'FVC' AND .dbo.TESTEDOCUMENTI.ESERCIZIO = YEAR(DATEADD(year,-1,GETDATE())));
------------------------------2 Previous years -----
SET #Fatt2AnniPrecedenti =
(SELECT '€ '+ REPLACE(CONVERT(varchar, CAST(SUM(TOTIMPONIBILE) AS money), 105),',','.') FROM .dbo.TESTEDOCUMENTI
WHERE CODCLIFOR = #CodiceCliente AND .dbo.TESTEDOCUMENTI.TIPODOC = 'FVC' AND .dbo.TESTEDOCUMENTI.ESERCIZIO = YEAR(DATEADD(year,-2,GETDATE())));
----------- Take the last document discount and set to variable -----
SET #Sconto =
(SELECT DISTINCT MAX(SCONTORIGA)
FROM .dbo.TESTEDOCUMENTI
WHERE SCONTORIGA IS NOT NULL AND CODCLIFOR = #CodiceCliente AND (.dbo.TESTEDOCUMENTI.TIPODOC = 'PCL' OR .dbo.TESTEDOCUMENTI.TIPODOC = 'ORC' ) AND .dbo.TESTEDOCUMENTI.DATADOC BETWEEN #datada AND #dataa);
--------------------------verify condition---THERE IS THE TRUOBLES----
---------------------------PREVIOUS YEAR SALES VOLUME----
IF #FattAnnoCorrente IS NULL SET #FattAnnoCorrente = '0'
IF #FattAnnoPrecedente IS NULL SET #FattAnnoPrecedente = '0'
IF #Fatt2AnniPrecedenti IS NULL SET #Fatt2AnniPrecedenti = '0'
IF #FattAnnoPrecedente = '0' goto fatturatocorrente;
IF (#FattAnnoPrecedente > '0' and #FattAnnoPrecedente < #40) and #Sconto < '40' goto finescript;
IF (#FattAnnoPrecedente > #40 and #FattAnnoPrecedente < #50 ) and (#Sconto > '40' and #Sconto < '50') goto finescript;
IF (#FattAnnoPrecedente > #50 and #FattAnnoPrecedente < #60 ) and (#Sconto > '50' and #Sconto < '60') goto finescript;
IF (#FattAnnoPrecedente > #60 and #FattAnnoPrecedente < #70 ) and (#Sconto > '60' and #Sconto < '70') goto finescript;
IF (#FattAnnoPrecedente > #70 and #FattAnnoPrecedente < #80 ) and (#Sconto > '70' and #Sconto < '80') goto finescript;
IF (#FattAnnoPrecedente > #80 and #FattAnnoPrecedente < '999999999999999999' ) and #Sconto > '80' goto finescript;
------------------------------------FIND THE SUGESTED DISCOUNT ------ THIS IS WRONG
IF ((#FattAnnoPrecedente > '0' and #FattAnnoPrecedente < #40 ))
SET #ScontoPrevisto = 'inferiore al 40%';
IF ((#FattAnnoPrecedente > #40 and #FattAnnoPrecedente < #50 ) )
SET #ScontoPrevisto = 'compreso tra 40% e 50%';
IF ((#FattAnnoPrecedente > #50 and #FattAnnoPrecedente < #60 ) )
SET #ScontoPrevisto = 'compreso tra 50% e 60%';
IF ((#FattAnnoPrecedente > #60 and #FattAnnoPrecedente < #70 ) )
SET #ScontoPrevisto = 'compreso tra 60% e 70%';
IF ((#FattAnnoPrecedente > #70 and #FattAnnoPrecedente < #80 ) )
SET #ScontoPrevisto = 'compreso tra 70% e 80%';
IF ((#FattAnnoPrecedente > #80 and #FattAnnoPrecedente < '999999999999999999' ) )
SET #ScontoPrevisto = 'superiore all"80%';
SET #AnnoConsiderato = 'ANNO PRECEDENTE';
fatturatocorrente:
------------USE CURRENT YEAR IF PREVIOUS SALES VOLUME IS 0---------
IF #FattAnnoPrecedente NOT LIKE '0' goto fatturatoesistente;
IF (#FattAnnoCorrente > '0' and #FattAnnoCorrente < #40 ) and #Sconto < '40' goto finescript;
IF (#FattAnnoCorrente > #40 and #FattAnnoCorrente < #50 ) and (#Sconto > '40' and #Sconto < '50') goto finescript;
IF (#FattAnnoCorrente > #50 and #FattAnnoCorrente < #60 ) and (#Sconto > '50' and #Sconto < '60') goto finescript;
IF (#FattAnnoCorrente > #60 and #FattAnnoCorrente < #70 ) and (#Sconto > '60' and #Sconto < '70') goto finescript;
IF (#FattAnnoCorrente > #70 and #FattAnnoCorrente < #80 ) and (#Sconto > '70' and #Sconto < '80') goto finescript;
IF (#FattAnnoCorrente > #80 and #FattAnnoCorrente < '999999999999999999' ) and #Sconto > '80' goto finescript;
------------------------------------FIND SUGGESTED DISCOUNT ------
--SET #FattAnnoCorrente = '1';
IF ((#FattAnnoCorrente > '0' and #FattAnnoCorrente < #40 ))
SET #ScontoPrevisto = 'inferiore al 40%';
IF ((#FattAnnoCorrente > #40 and #FattAnnoCorrente < #50 ))
SET #ScontoPrevisto = 'compreso tra 40% e 50%';
IF ((#FattAnnoCorrente > #50 and #FattAnnoCorrente < #60 ))
SET #ScontoPrevisto = 'compreso tra 50% e 60%';
IF ((#FattAnnoCorrente > #60 and #FattAnnoCorrente < #70 ))
SET #ScontoPrevisto = 'compreso tra 60% e 70%';
IF ((#FattAnnoCorrente > #70 and #FattAnnoCorrente < #80 ))
SET #ScontoPrevisto = 'compreso tra 70% e 80%';
IF ((#FattAnnoCorrente > #80 and #FattAnnoCorrente < '999999999999999999'))
SET #ScontoPrevisto = 'superiore all"80%';
SET #AnnoConsiderato = 'ANNO CORRRENTE';
IF #Sconto LIKE '0.0%' SET #ScontoPrevisto = 'da stabilire in base alla merce ordinata'
fatturatoesistente:
-----------
--- HERE THERE WAS SOME TABLES CALLED BELOW BUT THEY WORK FINE, SO I REMOVED THEM ---
---------------------------------
---HTML EMAIL BODY SET WITH ALL VARIABLES, ALL WORKING FINE BUT THE #SCONTOPREVISTO is the wrong one----
SET #Email =
N'......HTML CODE....' + #ScontoPrevisto + '..HTML CODE...';
SET #oggettomail = 'ERRATA SCONTISTICA PER ' + #Cliente;
IF #Emailis null goto finescript;
EXEC msdb.dbo.sp_send_dbmail
#recipients = 'email#gmail.com',
#subject = #oggettomail,
#body = #Email,
#body_format = 'HTML' ;
finescript:
--take the next customerE---
FETCH NEXT FROM c INTO #CodiceCliente,#Cliente
END
--clean---
CLOSE c
DEALLOCATE c
The result of this query for #ScontoPrevisto, suggested discount is wrong, it is between 70% and 80 % but as you see the previous year sales volume is about 25000 so the right discount must be 50-60%.
I dont' understand why. Instead for some customer, reslt is good.
Another customer has
Sales Volume 2016--->0
Sales Volume 2015 ---> 0
Discount 60%
Result is greater then 80 % instead to be smaller than 40 %.
I wait for your answer. Thank you guys!
I have a list of timestamp tuples of the form List((startTime,endTime)), which are basically denoting periods of time throughout the day.
For example:
(("2016-03-28 14:00:00","2016-03-28 15:00:00"),
("2016-03-28 17:00:00","2016-03-28 21:00:00"),
("2016-03-28 01:00:00","2016-03-28 13:00:00"))
I want to get a list of the durations which are not included in this list.
So the output should be:
(("2016-03-28 00:00:00","2016-03-28 01:00:00"),
("2016-03-28 13:00:00","2016-03-28 14:00:00"),
("2016-03-28 15:00:00","2016-03-28 17:00:00"),
("2016-03-28 17:00:00","2016-03-28 24:00:00"))
Can anyone suggest a good and efficient way of doing that in Scala?
The naive solution that I've tried so far is as follows:
import java.sql.Timestamp
import scala.collection.mutable.ListBuffer
def comparator(first: (Timestamp,Timestamp), second: (Timestamp, Timestamp)) = first._2.getTime <= second._1.getTime
val data = List((Timestamp.valueOf("2016-03-28 00:00:00"),Timestamp.valueOf("2016-03-28 10:00:00")),
(Timestamp.valueOf("2016-03-28 12:00:00"),Timestamp.valueOf("2016-03-28 15:00:00")),
(Timestamp.valueOf("2016-03-28 23:00:00"),Timestamp.valueOf("2016-03-28 23:59:59")),
(Timestamp.valueOf("2016-03-28 16:00:00"),Timestamp.valueOf("2016-03-28 21:00:00"))
).sortWith(comparator)
var emptySlots = new ListBuffer[(Timestamp,Timestamp)]()
var currTime = Timestamp.valueOf("2016-03-28 00:00:00")
var index = 0
var cond = 0
while(cond == 0){
if (currTime.compareTo(Timestamp.valueOf("2016-03-28 23:59:59")) < 0 && index >= data.size){
emptySlots += ((currTime,Timestamp.valueOf("2016-03-28 23:59:59") ))
cond = 1
}
else if(index >= data.size)
{
cond = 1
}
else if(currTime.compareTo(data(index)._1) < 0) {
emptySlots += ((currTime, data(index)._1))
currTime = data(index)._2
index += 1
}
else if(currTime.compareTo(data(index)._1) >= 0 && currTime.compareTo(data(index)._2) < 0 ) {
currTime = data(index)._2
index += 1
}
else if(currTime.compareTo(data(index)._1) > 0 && currTime.compareTo(data(index)._2) > 0 ) {
index += 1
}
}
emptySlots.toList