I have this: $(document).ready(function() { $('input[type="button"]').click(function() { var sum = 0, count = 0, result; $('input[type="text"]').each(function() { var val = Number( $(this).val() ); if (val && val >= 0) { sum += Number(val); count++; } }); the error is that it does not take zero into account, for example, 10 and 0 should average out to 5, not 10. result = (count > 0) ? sum/count : 'no values found'; $('#result').html( result ); }); }); How can I make it account for the number 0 when it figures out averages?

Member Avatar
Member Avatar
+0 forum 1

So I have this OpenGL program that displays a cube using gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); And it allows users to modify/rotate it along the x, y and z axis using input. Right now it looks it works pretty well, however, it terminates once the image is displayed according to the users input (on wether to rotate along the x, y or z axis). How can I modify this program so you can rotate it without it terminating? As in, displaying only the first rotation during the first input. Or to put it simply, how can …

Member Avatar
Member Avatar
+0 forum 1

1. What happens when you add an element to a vector that is already at capacity? Does std::vector have a "capacity"? 2. In C++ and OOP in general, what do you call a design where a Person class inherits from Head, Arm, Body, Leg classes instead of the other way around? Why would anyone do this?

Member Avatar
Member Avatar
+0 forum 3

I tested and successfully used this SQL code below to input data into a database. INSERT INTO hraps (id, firstname, lastname, gender, year_of_1st_rappel, count_offset_proficiency, count_offset_operational, spotter) values(111111, 'World', 'Hello', 'Male', '2007', '1', '2', '0') Now I'm trying to integrate it into PHP like this: $query = "INSERT INTO hraps (firstname, lastname, gender, year_of_1st_rappel, count_offset_proficiency, count_offset_operational, spotter) " ."values('".$this->firstname."','".$this->lastname."','".$this->gender."','".$this->year_of_1st_rappel."',".$this->count_offset_proficiency.",".$this->count_offset_operational.",".$this->spotter.") returning id into :id"; $dbid = ""; $binds = array(); $binds[] = array("name" => ":id", "value" => &$dbid, "length" => 128); //echo $query; $result = mydb::cxn()->query($query, $binds); $this->id = $dbid; But nothing gets inserted and I'm not getting any error. The only …

Member Avatar
Member Avatar
+0 forum 4

Hello. I received some code that has a section in which the variable $DB is established. $DB =& new DB($db_username, $db_password, $db_dsn, false); It does this by calling a function named DB, which is shown here below. /** * Constructor * * will set $DB->error and return false if login fails * * @param string $user * @param string $password * @param string $db_name * @param bool $persistent Should this be a persistent db connection ? * @param integer $int_mode * @return bool **/ function DB ( $user, $password, $db_name, $persistent=TRUE, $int_mode=OCI_COMMIT_ON_SUCCESS ) { $this->_valid_connection = false; $this->query_count = 0; …

Member Avatar
Member Avatar
+0 forum 2

Hello, I am just playing around with PHP and I have a silly little little login page, with the username and password hard coded in (not secure, I know). They are: username and password, respectively. Once logged in, there is a message saying I am logged in and a form shows up too. I'm just curious, how come when I log in, the HTML block that shows the username and password fields does not go away? It stays there even when I'm logged in. Can somebody please tell me what I'm doing wrong. <?php //ini_set('display_errors', 'On'); //error_reporting(E_ALL | E_STRICT); require_once …

Member Avatar
Member Avatar
+0 forum 4

Hello everyone, I have a PHP form that connects to an oracle DB and should send data to the database when the form is submitted, but I can't figure out why it's not loading any of the data into the database, everything seems to be correct (though this is my first time attempting something like this, so I am likely wrong). Is there something wrong with the way in which I've structured this page, or something wrong with the way I'm binding variables? Why isn't this properly working? Note: I changed the connect string to a fake one for security. …

Member Avatar
Member Avatar
+0 forum 7

Hello, I am using the tutorial from Oracle's site on how to connect to a database in PHP using code similar to the one shown below. <?php // Create connection to Oracle $conn = oci_connect("phphol", "welcome", "//localhost/orcl"); $query = 'select * from departments'; $stid = oci_parse($conn, $query); $r = oci_execute($stid); // Fetch each row in an associative array print '<table border="1">'; while ($row = oci_fetch_array($stid, OCI_RETURN_NULLS+OCI_ASSOC)) { print '<tr>'; foreach ($row as $item) { print '<td>'.($item !== null ? htmlentities($item, ENT_QUOTES) : '&nbsp').'</td>'; } print '</tr>'; } print '</table>'; ?> Lets say for example, once I have queried the data …

Member Avatar
Member Avatar
+0 forum 4

The code below seems to work great in Google Chrome, it hides a question in a div unless the question before it is answered. However, it doesn't seem to work at all in I.E 8. Can someone give me a solution on how to make it work in both browswers please? Thank you in advance <label for="cell">3. Do you currently have a cell phone? (Y/N)</label> <input type="checkbox" name="cell" id="cell" data-on="Yes" data-off="No" /> <div class="hide_if_no"> <label for="blackBerry">4. If YES, is the cell phone a BlackBerry? (Y/N)</label> <input type="checkbox" name="blackBerry" id="blackBerry" data-on="Yes" data-off="No" /> </div> <style> input[type=checkbox] ~ div.hide_if_no {display:none} input[type=checkbox]:checked ~ …

Member Avatar
Member Avatar
+0 forum 7

Here is some code (snippet) from a function I have that takes a users "user_name" and "password" as parameters. There is an if else statement that triggers along the way, basically, if there is a value $v, then it look ups the users user_name and password in a table and appends the @gmail part to it (so that the input username matches the email in the database) and if they are equal, it will log them in, otherwise it will display a message stating that there was an error while logging in. The trouble is, I can't get the error …

Member Avatar
Member Avatar
+0 forum 6

I'm new to PHP and was given a code snippet that looks like this: { $DB = new DB('xxxxxx','oooooo','gggggg'); $return_result = false; $this->clear_data(); $m = new xmlrpcmsg( 'ldapxml.authorize' , array( new xmlrpcval($user_name, "string") , new xmlrpcval($password, "string") ) ); // this is just a temp server for now $c = new xmlrpc_client(XMLRPC_CLIENT_PATH, XMLRPC_CLIENT_SERVER, XMLRPC_CLIENT_PORT); $c->return_type = 'phpvals'; $r = $c->send($m); if ( !$r->faultCode() ) { $v = $r->value(); if ( $v ) { $return_result = true; $this->put('username', $user_name); $this->put('IP', $_SERVER['REMOTE_ADDR']); $this->put($this->_valid_session_flag, 1); // grab the users info $m = new xmlrpcmsg( 'ldapxml.getAttibutes' , array( new xmlrpcval($user_name, "string") , new xmlrpcval($password, …

Member Avatar
Member Avatar
+0 forum 9

My code(below) displays only one "message" at a time and then prompts the user to delete the message in order to create a new one. How can I make it so that the user can constantly add new messages without having to delete the previous message? [CODE]import java.security.SecureRandom; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import com.google.appengine.api.datastore.DatastoreService; import com.google.appengine.api.datastore.DatastoreServiceFactory; import com.google.appengine.api.datastore.Entity; import com.google.appengine.api.datastore.Key; import com.google.appengine.api.datastore.Query; import com.google.appengine.api.datastore.Query.FilterOperator; import com.google.appengine.api.datastore.Query.SortDirection; import com.google.appengine.api.datastore.Text; // The application design is that authenticated users have zero or one messages. // // This class is not thread safe because it is possible to create 2 messages for …

Member Avatar
Member Avatar
+0 forum 1

Hi there. I have a few hundred/thousand macro enabled spreadsheets that need to be uploaded to a database. The spreadsheets have a button that copies the data over to the database and it prompts the user for a username and password in order to do so (same for all files). I am attempting to find a way to write a program that would allow me to access each of the spreadsheets automatically and upload them to the database but I'm not sure how to start and I haven't found a lot of documentation on doing somethings similar. Can someone get …

Member Avatar
Member Avatar
+0 forum 1

Writing a small program that requires me to convert strings to doubles and then back to strings. Right now, the code compiles but the answer is wrong, even though I am using an algorithm that I know is right in C++. Can someone tell me what I'm doing wrong? The answer that comes out always very large and random. [CODE] else{ //Converting Strings to Double INT's double myMonths = [monthsString doubleValue]; double myBalance = [balanceString doubleValue]; double myInterest = [interestString doubleValue]; //Payment Algorithm myInterest = (myInterest/100)/12; double AlmostDone = (myInterest * pow(1 + myInterest, myMonths)) * (myBalance/(pow(1 + myInterest, myMonths) …

Member Avatar
Member Avatar
+0 forum 1

Hello all, I am building a small file system in c++ that builds a table in a file called test.txt from information on another file. I am trying to copy the information over and then access a specific part of it based on the date. The data is copied over to the filesystem but I cannot access it again. Can anyone tell me what I am doing wrong? I am putting in the files that do this perticular function below please let me know if you see any obvious mistakes. Every time I put in a date right now, it …

Member Avatar
Member Avatar
+0 forum 2

I am getting the following error: PII.cpp:266: error: 'struct std::string' has no member named 'getfirstblock' And I'm not sure how to fix it, since "int block" has to be equal to the firstblock of the file, how can I fix that error? Also, my "getfirstblock" function should return the block number of the first block in string file but I am not sure how to implement it correctly, any suggestions? Any help is appreciated, thanks in advance [CODE]#include <iostream> #include <fstream> #include <string> #include <vector> #include <sstream> #include <sstream> using namespace std; //Pdisk Class class Pdisk { public: Pdisk(); //default …

Member Avatar
Member Avatar
+0 forum 1

The End.