Search Results

Search found 137428 results on 5498 pages for 'using statement'.

Page 6/5498 | < Previous Page | 2 3 4 5 6 7 8 9 10 11 12 13  | Next Page >

  • CI PHP if statement w/ sql syntax

    - by Kevin Brown
    This is a quick syntax question... I need to block out an HTML element if two SQL statements are true w/ php. If the status = 'closed', and if the current user is logged in. I can figure out the calls, I just need to see an example of the syntax. :) So, If SQL status=closed, and if current_user=is_logged_in()...something like that.

    Read the article

  • Why it's not "if" and not "else"?

    - by Roman
    I have this code: $link = mysql_connect("localhost", "ctmanager", "pswsafgcsadfgG"); if ( ! $link ) die("I cannot connect to MySQL.<br>\n"); else print "Connection is established.<br>\n"; print "a"; if ( mysql_create_db("ct", $link) ) print "AAA"; else print "BBB"; print "2"; die(); And this is the output: Connection is established. a So, I cannot understand how it's possible that neither "AAA" no "BBB" is outputted. Is it because program dies at mysql_create_db?

    Read the article

  • Javascript height statement

    - by Sean
    This is not working and I can't figure out where I went wrong: <style> * { margin: 0px } div { height: 250px; width: 630px; overflow: hidden; vertical-align: top; position: relative; } iframe { position: absolute; left: -50px; top: -130px; } </style> <script> window.onload = function() { document.getElementsByTagName('body')[0].onkeyup = function(e) { var div = document.getElementById('capture'); if(e.keyCode == 70) { if(div.style.height == 250){ alert("Yes"); } else {alert("no");} } } }; </script>

    Read the article

  • Switch statement for string matching in JavaScript

    - by yaya3
    How do I write a swtich for the following conditional? If the url contains "foo", then settings.base_url is "bar". The following is achieving the effect required but I've a feeling this would be more manageable in a switch: var doc_location = document.location.href; var url_strip = new RegExp("http:\/\/.*\/"); var base_url = url_strip.exec(doc_location) var base_url_string = base_url[0]; //BASE URL CASES // LOCAL if (base_url_string.indexOf('xxx.local') > -1) { settings = { "base_url" : "http://xxx.local/" }; } // DEV if (base_url_string.indexOf('xxx.dev.yyy.com') > -1) { settings = { "base_url" : "http://xxx.dev.yyy.com/xxx/" }; } Thanks

    Read the article

  • PHP if statement - select two different get variables?

    - by arsoneffect
    Below is my example script: <li><a <?php if ($_GET['page']=='photos' && $_GET['view']!=="projects"||!=="forsale") { echo ("href=\"#\" class=\"active\""); } else { echo ("href=\"/?page=photos\""); } ?>>Photos</a></li> <li><a <?php if ($_GET['view']=='projects') { echo ("href=\"#\" class=\"active\""); } else { echo ("href=\"/?page=photos&view=projects\""); } ?>>Projects</a></li> <li><a <?php if ($_GET['view']=='forsale') { echo ("href=\"#\" class=\"active\""); } else { echo ("href=\"/?page=photos&view=forsale\""); } ?>>For Sale</a></li> I want the PHP to echo the "href="#" class="active" only when it is not on the two pages: ?page=photos&view=forsale or ?page=photos&view=projects

    Read the article

  • Better way of coding this if statment?

    - by HadlowJ
    Hi. I have another question for you very helpful people. I use a lot of if statements many of which are just repeated and im sure could be shortened. This is my current bit of code if (Globals.TotalStands <= 1) { ScoreUpdate.StandNo2.Visible = false; ScoreUpdate.ScoreStand2.Visible = false; ScoreUpdate.ScoreOutOf2.Visible = false; } if (Globals.TotalStands <= 2) { ScoreUpdate.StandNo3.Visible = false; ScoreUpdate.ScoreStand3.Visible = false; ScoreUpdate.ScoreOutOf3.Visible = false; } if (Globals.TotalStands <= 3) { ScoreUpdate.StandNo4.Visible = false; ScoreUpdate.ScoreStand4.Visible = false; ScoreUpdate.ScoreOutOf4.Visible = false; } if (Globals.TotalStands <= 4) { ScoreUpdate.StandNo5.Visible = false; ScoreUpdate.ScoreStand5.Visible = false; ScoreUpdate.ScoreOutOf5.Visible = false; } if (Globals.TotalStands <= 5) { ScoreUpdate.StandNo6.Visible = false; ScoreUpdate.ScoreStand6.Visible = false; ScoreUpdate.ScoreOutOf6.Visible = false; } if (Globals.TotalStands <= 6) { ScoreUpdate.StandNo7.Visible = false; ScoreUpdate.ScoreStand7.Visible = false; ScoreUpdate.ScoreOutOf7.Visible = false; } if (Globals.TotalStands <= 7) { ScoreUpdate.StandNo8.Visible = false; ScoreUpdate.ScoreStand8.Visible = false; ScoreUpdate.ScoreOutOf8.Visible = false; } as you can see there is a huge amount of code to do something simple (which i do on a few other forms as well and im sure there must be a better way of coding this that gets the same result? Im a code noob so please be gentle, code is c# and software is visual studio 2008 pro. Thanks

    Read the article

  • PHP: prepared statement, IF statement help needed

    - by JGreig
    I have the following code: $sql = "SELECT name, address, city FROM tableA, tableB WHERE tableA.id = tableB.id"; if (isset($price) ) { $sql = $sql . ' AND price = :price '; } if (isset($sqft) ) { $sql = $sql . ' AND sqft >= :sqft '; } if (isset($bedrooms) ) { $sql = $sql . ' AND bedrooms >= :bedrooms '; } $stmt = $dbh->prepare($sql); if (isset($price) ) { $stmt->bindParam(':price', $price); } if (isset($sqft) ) { $stmt->bindParam(':price', $price); } if (isset($bedrooms) ) { $stmt->bindParam(':bedrooms', $bedrooms); } $stmt->execute(); $result_set = $stmt->fetchAll(PDO::FETCH_ASSOC); What I notice is the redundant multiple IF statements I have. Question: is there any way to clean up my code so that I don't have these multiple IF statements for prepared statements?

    Read the article

  • Explicit or implicit execution control statement use

    - by Andrei Rinea
    I sometimes use if (this._currentToolForeColor.HasValue) return this._currentToolForeColor.Value; else throw new InvalidOperationException(); other times I use if (this._currentToolForeColor.HasValue) return this._currentToolForeColor.Value; throw new InvalidOperationException(); The two are equivalent, I know, but I am not sure which is the best and why. This goes even further as you can use other execution-control statements such as brake or continue : while(something) { if(condition) { DoThis(); continue; } else break; } versus while(something) { if(condition) { DoThis(); continue; } break; } EDIT 1 : Yes the loop example(s) suck because they are synthetic (i.e.: made up for this question) unlike the first which is practical.

    Read the article

  • How to make a correct if-statement to filter out values from a xml-file

    - by Garreth 00
    Edit 3: As requested, I'm trying to simplify my question. Here is a sample of some of my data from a xml file: <entry> <title>Entry 1</title> <f:max_value_a>499 999</f:max_value_a> <f:max_value_b>999 999</f:max_value_b> <f:min_value_a>0</f:min_value_a> <f:min_value_b>500 000</f:min_value_b> <f:min_value_c>1 000 000</f:min_value_c> <f:value_for_a>5,10</f:value_for_a> <f:value_for_b>4,50</f:value_for_b> <f:value_for_c>3,90</f:value_for_c> </entry> <entry> <title>Entry 2</title> <f:min_value_a>0</f:min_value_a> <f:value_for_a>4,20</f:value_for_a> </entry> <entry> <title>Entry 3</title> <f:max_value_a>1 999 999</f:max_value_a> <f:min_value_a>100 000</f:min_value_a> <f:min_value_b>2 000 000</f:min_value_b> <f:value_for_a>3,735</f:value_for_a> <f:value_for_b>3,445</f:value_for_b> </entry> f:value_for_d is the highest value, and f:value_for_c is lower than d, and so on. I have a dynamic targetvalue (lets just go with 2 000 000 in this example) I want to get the value where max_value is greater than the targetvalue, but sometimes max_value is not defined and then set to "0". "0" in max_value should mean unlimited "roof". The min_value can not be greater than targetvalue, but sometimes min_value is not defined and then set to "0". "0" min_value should mean a unlimited "floor". I have tried with this code if ($value_for_d > 0 ){ if (($min_value_d <= $targetvalue) xor ($min_value_d == 0)){ if (($max_value_d >= $targetvalue) xor ($max_value_d == 0)){ $query_result = TRUE; $value = $value_for_d; } } }elseif ($value_for_c > 0 ){ if (($min_value_c <= $targetvalue) xor ($min_value_c == 0)){ if (($max_value_c >= $targetvalue) xor ($max_value_c == 0)){ $query_result = TRUE; $value = $value_for_c; } } }elseif ($value_for_b > 0 ){ if (($min_value_b <= $targetvalue) xor ($min_value_b == 0)){ if (($max_value_b >= $targetvalue) xor ($max_value_b == 0)){ $query_result = TRUE; $value = $value_for_b; } } }elseif ($value_for_a > 0 ){ if (($min_value_a <= $targetvalue) xor ($min_value_a == 0)){ if (($max_value_a >= $targetvalue) xor ($max_value_a == 0)){ $query_result = TRUE; $value = $value_for_a; } } } If I run this code with a targetvalue of "2 000 000", I get this result: Entry 1 - 3.9 (correct value is 3.9) Entry 2 - 0 (correct value is 4.2) Entry 3 - 3.445 (correct value is 3.445) If I set the targetvalue to even lower, to 500 000, I get 0 on all my entries.

    Read the article

  • jQuery / Javascript if statement speed

    - by Sam
    Given: var isIE = $.browser.msie && !$.support.opacity, isIE6 = isIE && $.browser.version < 7; Which would be faster: if(isIE6){ doSomething(); } else { doSomethingElse(); } OR if(!isIE6){ doSomethingElse(); } else { doSomething(); } Are they exactly the same in terms of speed?

    Read the article

  • Wrong logic in If Statement?

    - by Charles
    $repeat_times = mysql_real_escape_string($repeat_times); $result = mysql_query("SELECT `code`,`datetime` FROM `fc` ORDER by datetime desc LIMIT 25") or die(mysql_error()); $output .=""; $seconds = time() - strtotime($fetch_array["datetime"]); if($seconds < 60) $interval = "$seconds seconds"; else if($seconds < 3600) $interval = floor($seconds / 60) . " minutes"; else if($seconds < 86400) $interval = floor($seconds / 3600) . " hours"; else $interval = floor($seconds / 86400) . " days"; while ($fetch_array = mysql_fetch_array($result)) { $fetch_array["code"] = htmlentities($fetch_array["code"]); $output .= "<li><a href=\"http://www.***.com/code=" . htmlspecialchars(urlencode($fetch_array["code"])) . "\" target=\"_blank\">" . htmlspecialchars($fetch_array["code"]) . "</a> (" . $interval . ") ago.</li>"; } $output .=""; return $output; Why is this returning janice (14461 days) instead of janice (15 minutes ago) The datetime function table has the DATETIME type in my table so it's returning a full string for the date.

    Read the article

  • Update table with if statement PS/SQL

    - by Matt
    I am trying to do something like this but am having trouble putting it into oracle coding. BEGIN IF ((SELECT complete_date FROM task_table WHERE task_id = 1) IS NULL) THEN UPDATE task_table SET complete_date = //somedate WHERE task_id = 1; ELSE UPDATE task_table SET complete_date = NULL; END IF; END; But this does not work i also tried IF EXISTS(SELECT complete_date FROM task_table WHERE task_id = 1) with no luck

    Read the article

  • 42000 Syntax error in query when executing prepared statement

    - by Griff McGriff
    I have been pulling my hair out trying to swap my current script over to PDO. I have simplified the MySQL query for this example, but the error remains even with this version. $sql = 'SELECT * FROM :table WHERE lastUpdate > :appDate'; try{ $db = connect(); $stmt = $db->prepare($sql); $stmt->bindParam(':table', $table); $stmt->bindParam(':appDate', $appDate); foreach($tablesToCheck as $table){ $stmt->execute(); $resultset[] = $stmt->fetchAll(); } } catch(PDOException $e){ print 'Error!: '.$e->getMessage().'<br/>'; }//End try catch $stmt-errorInfo() returns: ( [0] => 42000 [1] => 1064 [2] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''GroupName' WHERE lastUpdate > NULL' at line 1 )

    Read the article

  • C# using namespace directive in nested namespaces

    - by MoSlo
    Right, I've usually used 'using' directives as follows using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace AwesomeLib { //awesome award winning class declarations making use of Linq } i've recently seen examples of such as using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace AwesomeLib { //awesome award winning class declarations making use of Linq namespace DataLibrary { using System.Data; //Data access layers and whatnot } } Granted, i understand that i can put USING inside of my namespace declaration. Such a thing makes sense to me if your namespaces are in the same root (they organized). System; namespace 1 {} namespace 2 { System.data; } But what of nested namespaces? Personally, I would leave all USING declarations at the top where you can find them easily. Instead, it looks like they're being spread all over the source file. Is there benefit to the USING directives being used this way in nested namespaces? Such as memory management or the JIT compiler?

    Read the article

  • SQL SERVER – Not Possible – Delete From Multiple Table – Update Multiple Table in Single Statement

    - by pinaldave
    There are two questions which I get every single day multiple times. In my gmail, I have created standard canned reply for them. Let us see the questions here. I want to delete from multiple table in a single statement how will I do it? I want to update multiple table in a single statement how will I do it? The answer is – No, You cannot and you should not. SQL Server does not support deleting or updating from two tables in a single update. If you want to delete or update two different tables – you may want to write two different delete or update statements for it. This method has many issues – from the consistency of the data to SQL syntax. Now here is the real reason for this blog post – yesterday I was asked this question again and I replied my canned answer saying it is not possible and it should not be any way implemented that day. In the response to my reply I was pointed out to my own blog post where user suggested that I had previously mentioned this is possible and with demo example. Let us go over my conversation – you may find it interesting. Let us call the user DJ. DJ: Pinal, can we delete multiple table in a single statement or with single delete statement? Pinal: No, you cannot and you should not. DJ: Oh okey, if that is the case, why do you suggest to do that? Pinal: (baffled) I am not suggesting that. I am rather suggesting that it is not possible and it should not be possible. DJ: Hmm… but in that case why did you blog about it earlier? Pinal: (What?) No, I did not. I am pretty confident. DJ: Well, I am confident as well. You did. Pinal: In that case, it is my word against your word. Isn’t it? DJ: I have proof. Do you want to see it that you suggest it is possible? Pinal: Yes, I will be delighted too. (After 10 Minutes) DJ: Here are not one but two of your blog posts which talks about it - SQL SERVER – Curious Case of Disappearing Rows – ON UPDATE CASCADE and ON DELETE CASCADE – Part 1 of 2 SQL SERVER – Curious Case of Disappearing Rows – ON UPDATE CASCADE and ON DELETE CASCADE – T-SQL Example – Part 2 of 2 Pinal: Oh! DJ: I know I was correct. Pinal: Well, oh man, I did not mean there what you mean here. DJ: I did not understand can you explain it further. Pinal: Here we go. The example in the other blog is the example of the cascading delete or cascading update. I think you may want to understand the concept of the foreign keys and cascading update/delete. The concept of cascading exists to maintain data integrity. If there primary keys get deleted the update or delete reflects on the foreign key table to maintain the key integrity and data consistency. SQL Server follows ANSI Entry SQL with regard to referential integrity between PrimaryKey and ForeignKey columns which requires the inserting, updating, and deleting of data in related tables to be restricted to values that preserve the integrity. This is all together different concept than deleting multiple values in a single statement. When I hear that someone wants to delete or update multiple table in a single statement what I assume is something very similar to following. DELETE/UPDATE Table 1 (cols) Table 2 (cols) VALUES … which is not valid statement/syntax as well it is not ASNI standards as well. I guess, after this discussion with DJ, I realize I need to do a blog post so I can add the link to this blog post in my canned answer. Well, it was a fun conversation with DJ and I hope it the message is very clear now. Reference: Pinal Dave (http://blog.SQLAuthority.com) Filed under: PostADay, SQL, SQL Authority, SQL Joins, SQL Query, SQL Server, SQL Tips and Tricks, T SQL, Technology

    Read the article

  • ClearTrace Supports Statement Level Events

    - by Bill Graziano
    One of the requests I get on a regular basis is to capture the performance of statement level events.  The latest beta has this feature available.  If you’re interested in this I’d like to get some feedback. I handle the SP:StmtCompleted and the SQL:StmtCompleted events.  These report CPU, reads, writes and duration. I’m not in any way saying it’s a good idea to trace these events.  Use with caution as this can make your traces much larger. If there are statement level events in the trace file they will be processed.  However the query screen displays batch level *OR* statement level events.  If it did both we’d be double counting. I don’t have very many traces with statement completed events in them.  That means I only did limited testing of how it parses these events.  It seems to work well so far though.  Your feedback is appreciated. If you ever write loops or cursors in stored procedures you’re going to get huge trace files.  Be warned. I also fixed an annoying bug where ClearTrace would fail and tell you a value had already been added.  This is a result of the collection I use being case-sensitive and SQL Server not being case-sensitive.  I thought I had properly coded around that but finally realized I hadn’t.  It should be fixed now. If you have any questions or problems the ClearTrace support forum is the best place for those.

    Read the article

  • inserting datetimes into database using java

    - by gordatron
    Hi, I am wanting to insert a datetime into a MySql data base using Java and a prepared statement: Calendar cal = Calendar.getInstance(); PreparedStatement stmnt = db.PreparedStatement("INSERT INTO Run " + "(Time) VALUE (?) "); stmnt.setDate(1, new java.sql.Date(cal.getTime())); stmnt.executeQuery(); NOTE: thre is currently an error - cannot find symbol (java.sql.Date) line 4 here db is an instance of a sort of wrapper class that exposes what I need from java.sql - its just getting a prepared statement from my connection object here. Time (the column) is a date time in my database, and I can only see sedDate and setTime method but I want to store both - also my code does not work anyway ;-) if anyone could give me some pointers on inserting a combined date time (current time would be a great help as that's my first goal) into a MySql DB using a prepared statement I would be very grateful. Thanks

    Read the article

  • If-Else V.S. Switch end of flow

    - by Chris Okyen
    I was wondering the if if-else statements, is like a switch statement that does not have a break statement.To clarify with an example, will the if-else statement go through all the boolean expressions even if comes to one that is true before the final one... I.E., if boolean_expression_1 was true, would it check if boolean_expression_2 is true? If not, why do switch statements need break statements but if-else statements do not? And if they do, I ask the opposite sort question proposed in the previous sentence. if( boolean_expression_1 ) statement_1 else if( boolean_expression_2 ) statement_2 else default_statement switch( controlling_expression ) { case: ( A ) .... case: ( z ) }

    Read the article

  • Is there a list of common object that implement IDisposable for the using statement?

    - by SkippyFire
    I was wondering if there was some sort of cheat sheet for which objects go well with the using statement... SQLConnection, MemoryStream, etc. Taking it one step further, it would be great to even show the other "pieces of the puzzle", like how you should actually call connection.Close() before the closing using statement bracket. Anything like that exist? If not, maybe we should make one.

    Read the article

  • How to make multiple queries with PHP prepared statements (Commands out of sync error)

    - by Tirithen
    I'm trying to run three MySQL queries from a PHP script, the first one works fine, but on the second one I get the "Commands out of sync; you can’t run this command now" error. I have managed to understand that I need to "empty" the resultset before preparing a new query but I can't seem to understand how. I thought that $statement-close; would do that for me. Here is the relevant part of the code: <?php $statement = $db_conn->prepare("CALL getSketches(?,?)"); // Prepare SQL routine to check if user is accepted $statement->bind_param("is", $user_id, $loaded_sketches); // Bind variables to send $statement->execute(); // Execute the query $statement->bind_result( // Set return varables $id, $name, $description, $visibility, $createdby_id, $createdby_name, $createdon, $permission ); $new_sketches_id = array(); while($statement->fetch()) { $result['newSketches'][$id] = array( "name" => $name, "description" => $description, "visibility" => $visibility, "createdById" => $createdby_id, "createdByName" => $createdby_name, "createdOn" => $createdon, "permission" => $permission ); $new_sketches_id[] = $id; } $statement->close; // Close satement $new_sketches_ids = implode(",", $new_sketches_id); // Get the new sketches elements $statement = $db_conn->prepare("CALL getElements(?,'',?,'00000000000000')"); // Prepare SQL routine to check if user is accepted // The script crashes here with $db_conn->error // "Commands out of sync; you can't run this command now" $statement->bind_param("si", $new_sketches_ids, $user_id); // Bind variables to send $statement->execute(); // Execute the query $statement->bind_result( // Set return varables $id, $user_id, $type, $attribute_d, $attribute_stroke, $attribute_strokeWidth, $sketch_id, $createdon ); while($statement->fetch()) { $result['newSketches'][$sketch_id]['newElements']["u".$user_id."e".$id] = array( "type" => $type, "d" => $attribute_d, "stroke" => $attribute_stroke, "strokeWidth" => $attribute_strokeWidth, ); } $statement->close; // Close satement ?> How can I make the second query without closing and reopening the entire database connection?

    Read the article

  • SQL SERVER – A Puzzle – Swap Value of Column Without Case Statement

    - by pinaldave
    For the last few weeks, I have been doing Friday Puzzles and I am really loving it. Yesterday I received a very interesting question by Navneet Chaurasia on Facebook Page. He was asked this question in one of the interview questions for job. Please read the original thread for a complete idea of the conversation. I am presenting the same question here. Puzzle Let us assume there is a single column in the table called Gender. The challenge is to write a single update statement which will flip or swap the value in the column. For example if the value in the gender column is ‘male’ swap it with ‘female’ and if the value is ‘female’ swap it with ‘male’. Here is the quick setup script for the puzzle. USE tempdb GO CREATE TABLE SimpleTable (ID INT, Gender VARCHAR(10)) GO INSERT INTO SimpleTable (ID, Gender) SELECT 1, 'female' UNION ALL SELECT 2, 'male' UNION ALL SELECT 3, 'male' GO SELECT * FROM SimpleTable GO The above query will return following result set. The puzzle was to write a single update column which will generate following result set. There are multiple answers to this simple puzzle. Let me show you three different ways. I am assuming that the column will have either value ‘male’ or ‘female’ only. Method 1: Using CASE Statement I believe this is going to be the most popular solution as we are all familiar with CASE Statement. UPDATE SimpleTable SET Gender = CASE Gender WHEN 'male' THEN 'female' ELSE 'male' END GO SELECT * FROM SimpleTable GO Method 2: Using REPLACE  Function I totally understand it is the not cleanest solution but it will for sure work in giving situation. UPDATE SimpleTable SET Gender = REPLACE(('fe'+Gender),'fefe','') GO SELECT * FROM SimpleTable GO Method 3: Using IIF in SQL Server 2012 If you are using SQL Server 2012 you can use IIF and get the same effect as CASE statement. UPDATE SimpleTable SET Gender = IIF(Gender = 'male', 'female', 'male') GO SELECT * FROM SimpleTable GO You can read my article series on SQL Server 2012 various functions over here. SQL SERVER – Denali – Logical Function – IIF() – A Quick Introduction SQL SERVER – Detecting Leap Year in T-SQL using SQL Server 2012 – IIF, EOMONTH and CONCAT Function Let us clean up. DROP TABLE SimpleTable GO Question to you: I came up with three simple tricks where there is a single UPDATE statement which swaps the values in the column. Do you know any other simple trick? If yes, please post here in the comments. I will pick two random winners from all the valid answers. Winners will get 1) Print Copy of SQL Server Interview Questions and Answers 2) Free Learning Code for Online Video Courses I will announce the winners on coming Monday. Reference:  Pinal Dave (http://blog.SQLAuthority.com) Filed under: CodeProject, PostADay, SQL, SQL Authority, SQL Interview Questions and Answers, SQL Puzzle, SQL Query, SQL Server, SQL Tips and Tricks, SQLServer, T SQL, Technology

    Read the article

< Previous Page | 2 3 4 5 6 7 8 9 10 11 12 13  | Next Page >