if-statement

Strange PHP syntax

I've been working on PHP for some time but today when I saw this it came as new to me: if(preg_match('/foo.*bar/','foo is a bar')): echo 'success '; echo 'foo comes before bar'; endif; To my surprise it also runs without error. Can anyone enlighten me? Thanks to all :) ...

How to check whether a mysql select statement result has a value or not in php?

I have a textbox UserName and a Check Availability button next to it..... I have checked the availability by passing UserName textbox value..... But it doesn't seem to work.... Here is what i am doing? echo $UserName = $_GET['CheckUsername']; $_SESSION['state'] = $State; $queryres = "SELECT dUser_name FROM tbl_login WHERE dUser_name='$...

Putting a simple if-then statement on one line

I'm just getting into Python and I really like the terseness of the syntax. However; is there an easier way of writing an if-then statement so it fits on one line? For example; say I have the simple test: if count == N: count = 0 else: count = N + 1 is there a simpler way of writing this? I mean, in Objective-C I would write ...

T-SQL: if exists always return true ?

Hello, What do you think , does the Stored Procedure always return 1 ? I am concerned about the if exists(..) BEGIN DECLARE @IsUserExisting bit SET NOCOUNT ON IF Exists ( Select null FROM G_User WHERE SamAccountName = @SamAccountName AND NetBIOSDomainName = @NetBIOSDomainName ) BEGIN SET @IsUserExi...

iphone calls both if and else at the same time?

Hi, I need to determine what file type a file is and then perform a certain action for it. this seems to work fine for some types, however all media types such as videos and sound files get mixed up. I determine the file type by doing this: BOOL matchedMP3 = ([[rowValue pathExtension] isEqualToString:@"mp3"]); if (matchedMP3 == ...

Dealing with big IF statements in PHP

Hi everyone, Is there any good alternative for the plain if statements in PHP? I know about switch, but I'll guess that there's some more refined alternative out there that comes handy when working with really big if statements. Thanks a lot, ...

The Cash or Credit problem

If you go to a store and ask "Cash or Credit?" they might simply say "Yes." This doesn't tell you anything as you posed an OR statement. if(cash || credit) With humans it's possible that they might respond "Both" to that question, or "Only {cash | credit}." Is there a way (or operator) to force the a statement to return the TRUE portio...

Conditional operator in if-statement?

I've written the following if-statement in Java: if(methodName.equals("set" + this.name) || isBoolean() ? methodName.equals("is" + this.name) : methodName.equals("get" + this.name)) { ... } Is this a good practice to write such expressions in if, to separate state from condition? And can this expression be si...

Creating a MySQL trigger to verify data on another table

I am trying to set up a MySQL trigger that does the following: When someone inserts data into databaseA.bills, it verifies if databaseB.bills already has that row, if it doesn't, then it does an additional insert into databaseB.bills. Here is what I have: CREATE TRIGGER ins_bills AFTER INSERT ON databaseA.bills FOR EACH ROW BEGIN ...

What's the scope of a Python variable declared in an if statement?

I'm new to Python, so this is probably a simple scoping question. The following code in a Python file (module) is confusing me slightly: if __name__ == '__main__': x = 1 print x In other languages I've worked in, this code would throw an exception, as the x variable is local to the if statement and should not exist outside of it....

How to return a message from my repository class to my controller and then to my view in asp.net-mvc?

I use this for checking an existing emailId in my table and inserting it...It works fine how to show message to user when he tries to register with an existing mailId.... if (!taxidb.Registrations.Where(u => u.EmailId == reg.EmailId).Any()) { taxidb.Registrations.InsertOnSubmit(reg); taxidb.SubmitChanges(); } and my control...

Testing for undefined and null child objects in ActionsScript/Flex

Hi Everyone, I use this pattern to test for undefined and null values in ActionScript/Flex : if(obj) { execute() } Unfortunately, a ReferenceError is always thrown when I use the pattern to test for child objects : if(obj.child) { execute() } ReferenceError: Error #1069: Property child not found on obj and there is no defau...

PHP echo if post equals, help

I am trying to echo the action for my form if a post equals 'paypal' This is what I have: <?php if $_POST['method'] == 'paypal' echo 'action="paypal/process.php"' else echo 'action="moneybookers/process.php" '?> Do i need to print the variable before I do this? what am I doing wrong? I get this error: Parse error: syntax error, un...

Is using If, ElseIf, ElseIf better than using If, If, If?

Is there really any difference between using If(this) { } Else If(that) { } Else { } or using, If(this) { } If(that) { } Else { } ? Does one execute any faster? Does the compiler or architecture make any difference? ...

Is there any difference between these two "if" conditional statement?

First if condition if(Txt1.Text != "" && Txt2.Text != "") Second if condition if((Txt1.Text && Txt2.Text) != "") Is there any diff between these two conditional statement? ...

Echo text if value of variable equals zero

I have this code: <?php if ( $amount < 5 ) { echo 'Credit Balance low! You have'; echo $amount; echo ' remaining credits.'; } else { echo 'No recent alerts...'; } ?> Where it says echo $amount; I want to echo $00.00 if the value of $amount == 0. How would I include this in my code? ...

if else statements php

How do I get this to not display when you first go to the page??? if ($error) { echo "Error: $error<br/>"; } if ($keycode) { echo "Keycode: $keycode<br/>"; } ...

Help to implement if-statement with array values

Hi all. I have a following source code php+js: http://pastebin.org/277948 I want to rewrite it using pure JS, but can’t imagine the way. Any advices are appreciated. ...

short hand for chaining logical operators in javascript?

Is there a better way to write the following conditional in javascript? if ( value == 1 || value == 16 || value == -500 || value == 42.42 || value == 'something' ) { // blah blah blah } I hate having all of those logical ORs strung together. I'm wondering if there is some kind of shorthand. Thanks! ...

How can I use && in if in Ruby on Rails?

I tried the following && conditional for my if statement and I get a "bad range" error: <% if (from_today(contact, call.days) == 0..7) && (show_status(contact, call) == 'no status') %> Why and how can I fix it? The only other way I could do it was to have a second nested if statement and break it apart...not pretty :( ...