MySQL select with CONCAT condition

The aliases you give are for the output of the query – they are not available within the query itself. You can either repeat the expression: SELECT neededfield, CONCAT(firstname, ‘ ‘, lastname) as firstlast FROM users WHERE CONCAT(firstname, ‘ ‘, lastname) = “Bob Michael Jones” or wrap the query SELECT * FROM ( SELECT neededfield, … Read more

JavaScript: using a condition in switch case

This works: switch (true) { case liCount == 0: setLayoutState(‘start’); var api = $(‘#UploadList’).data(‘jsp’); api.reinitialise(); break; case liCount<=5 && liCount>0: setLayoutState(‘upload1Row’); var api = $(‘#UploadList’).data(‘jsp’); api.reinitialise(); break; case liCount<=10 && liCount>5: setLayoutState(‘upload2Rows’); var api = $(‘#UploadList’).data(‘jsp’); api.reinitialise(); break; case liCount>10: var api = $(‘#UploadList’).data(‘jsp’); api.reinitialise(); break; } The only thing necessary is switch(true){…} and for … Read more

Conditional with statement in Python

Python 3.3 and above Python 3.3 introduced contextlib.ExitStack for just this kind of situation. It gives you a “stack”, to which you add context managers as necessary. In your case, you would do this: from contextlib import ExitStack with ExitStack() as stack: if needs_with(): gs = stack.enter_context(get_stuff()) # do nearly the same large block of … Read more

Can I use conditional statements with EJS templates (in JMVC)?

Conditionals work if they’re structured correctly, I ran into this issue and figured it out. For conditionals, the tag before else has to be paired with the end tag of the previous if otherwise the statements will evaluate separately and produce an error. ERROR! <% if(true){ %> <h1>foo</h1> <% } %> <% else{ %> <h1>bar</h1> … Read more

Why do empty JavaScript arrays evaluate to true in conditional structures?

From http://www.sitepoint.com/javascript-truthy-falsy/ The following values are always falsy: false 0 (zero) 0n (BigInt zero) “” (empty string) null undefined NaN (a special Number value meaning Not-a-Number!) All other values are truthy, including “0” (zero in quotes), “false” (false in quotes), empty functions, empty arrays ([]), and empty objects ({}). Regarding why this is so, I … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)