if-statement

jQuery determine if ul has class OR another one

Hi, what is the right way to determine if an object has one class OR another one? The following is appearantly wrong.. if ($('#menu-item-49').hasClass('current-menu-item' || 'current-menu-parent') ) { $('ul.sub-menu ').css('display', 'block'); } Thanks! ...

Reasoning for alternate PHP syntax for conditional HTML

So, why does this work: <?php if (condition): ?> <!--html code here--> <?php endif; ?> But not simply this: <?php if (condition) { ?> <!--html code here--> <? } I figured it was just style preference, but I actually can't seem to get it to work the second way. Am I just doing something completely wrong? I can't see the ...

Outputting the name of the month instead of the number

I have a query which returns 3 fields, one of which is the month as a two digit number. I want to basically have it so if month == 1 output january, if month == 02 output febuary etc This is what I am trying, but this does not work at all, and prevent the entire column from being displayed in PHP. while ($row = mysql_fetch...

Easy if problem in vbscript

Hello, i try to copy the second line from a txt, that works great problem is now i try to make an if-statement that check the txt, is there something in line 2. Set fso = CreateObject("Scripting.FileSystemObject") Set MyFile = fso.CreateTextFile("testfile.txt", True) MyFile.WriteLine("" + LastMessage + "") MyFile.Close rownumber...

MYSQL if a select query returns 0 rows then another select query?

if (select * from table where x=1) returns 0 rows then i need (select * from table where x=2 [or some other query]). is it possible to do this in a single MYSQL query with a conditional statement? edit: all answers with 'UNION' work but only if both queries selects from the same table (or tables with the same number of columns). What if...

Amending Gridview according to table properties.

Hello all. I shall attempt to explain the scenario. I have a gridview I wish to amend according to the preferences a user may set. These preferences being stored within a table in a EDMX (tblPref). The table gives the prefernce i.e. Product, the Alias for the preference i.e. SKU and whether the Preference should be shown i.e. ShowProdu...

Stuck in a Clojure loop, need some guidance

Hi, I am stuck in a Clojure loop and need help to get out. I first want to define a vector (def lawl [1 2 3 4 5]) I do (get lawl 0) And get "1" in return. Now, I want a loop that get each number in the vector, so I do: (loop [i 0] (if (< i (count lawl)) (get lawl i) (recur (inc i)))) In my mind this is supposed...

'if' statements don't function correctly

I am writing some jQuery code that involves jumping from several functions. In one function, an 'if'-statement is used to select where the code will go next. The condition for the if statement is the value of a variable that was passed from the previous function. So, to clarify, a function passes a variable to another function, which the...

Simple PHP script help, if/else/timestamps/ less than / bit-shift

I am trying to make a timestamp function that checks which displays a time if it has been less than 24 hours and a date if it has been more. If anybody knows of a prebuilt way to do this please let me know. Anyways, I've started with this simple php which is suppose to return a number less than 86400 if $temprow1 or 2 are less than 8640...

A or B, not both, not neither

Ever since reading Clean Code I have been trying to keep my code descriptive and easy to understand. I have a condition where either A or B must be filled in. But not both. And not neither. Currently the if statement to check for this condition is hard to follow at a glance. How would you write the following to make it clear at a gl...

Inline If Statements in SQL

I wish to do something like this: DECLARE @IgnoreNulls = 1; SELECT Col1, Col2 FROM tblSimpleTable IF @IgnoreNulls BEGIN WHERE Col2 IS NOT NULL END ORDER BY Col1 DESC; The idea is to, in a very PHP/ASP.NET-ish kinda way, only filter NULLs if the user wishes to. Is this possible in T-SQL? Or do we need one large IF block like so: IF...

Javascript & Split Arrays

What I want to accomplish is simple. I want a button's text to change depending on what page your on. I start this by using the following: var loc_array = document.location.href.split('/'); Now that I have the url and split it in an array I can grab certain directories depending on the position, like so: if (loc_array[loc_array.leng...

jQuery 'If' statement string comparison not working.

I'm having a very hard time trying to do something very simple. Here's the code: if(data == 'success') { alert('foo'); } else { alert(data); } I've simplified it, but that's all that's necessary to understand what's going on. the variable 'data' is a result of an AJAX call, if that m...

Javascript: Why if(false) ?

I saw this in code. It blew my mind. <% if (false) { %> <script type="text/javascript" src="~/Scripts/jquery-1.3.2.js"></script> <% } %> This seems so patently illogical that it must be intentional. I can only assume that somehow this "came up", and somebody inserted this as a work-around. There are, of course, no comments. Why ...

PHP creating a while loop that is dependent on multiple variables that are independent of one another?

I'm stumped on this and my searches aren't turning up anything relevant.. I need to do a while loop that will continue if either of 2 variables are true... as far as I can tell you can't do a "while ($var = '' and $var2 = ''); so I tried this, basically I figured I could just set 2 different if statements so that it would change the vari...

.net template 'if null' check in vb - syntax?

I am new to .net completely and I just need to know the syntax, or possible functions to put in my if statement to check if <% If Model.contacts Is Null Then%> which isn't correct. Where Model.contacts comes from my ClientViewModel, and Model.contacts is of type System.Linq.IQueryable(Of Contact) Here is the code for addresses... <% ...

Elegantly escaping errors

I have statements such as @user = User.find(current_user.id) throughout my app. Sometimes a user might enter with a nil variable (such as a new user for whom current_user is nil). I'm sure the dumb way to do this would be to scatter if statements everywhere like... if current_user.exists? @user = User.find(current_user.id) else re...

IF EXIST C:\directory\ goto a else goto b problems windows XP batch files

Hi whenever i run the code below it occurs to me I have made a mistake using the if exist lines, as no matter whether the directory exists or not, it acts as if the line was never there... either that or its not reading the else line. echo off echo echo (c) Ryan Leach 2010 echo Stockmaster Backup System for exclusive use of Rive...

if condition not working

My aim is to take two strings and compare there ends if both of them ends with "ing","ed" or there ends do not match.It always says that strings do not match . #include <stdio.h> #include <conio.h> #include <string.h> int ised(char str[]); int ising(char str[]); int main() { char str1[30],str2[30]; printf("Enter 1st string:\n"...

django templates

How can i split cases for None and False in django templates. {%if x %} True {%else%} None and False - how i can split this cases? {%endif%} ...