-
Posts
5,717 -
Joined
-
Last visited
-
Days Won
6
Everything posted by Adam
-
If I was an investor I'd be asking 'how will this make me money?' From a developer point of view though, the idea sounds feasible. Although I have a few thoughts.. How would the user know this object ID? It sounds like you're asking them to provide the.. whatever equivalent of a product's manufacturer code just to access it. You can't really expect the user to go off to Google and spend five minutes trying to find it, because they just wouldn't do it. Also, I'm not really familiar with the website you mentioned, but do they allow you to crawl their website? All of them? How would you know which web service to use for each object ID? When writing a bot you have to consider that if they notice your requests to their website (i.e. you fire several a second, or over two seconds) they'll block you. At work we occasionally get requests through to block this IP or another, either because they're causing performance issues or they've just been noticed crawling the site a lot. You have to limit your connections to keep 'under the radar'. This may be different however, if it's just a single request as the user enters the content. Though if you do get blocked, would certain content on the website fail to work?
-
Looking for a more efficient to find and process multiple IDs
Adam replied to cyberRobot's topic in Javascript Help
There are other areas where incrementing the variable first does have an affect. For example: var x = 1; var y = x++; // value of y would be 1 var x = 1; var y = ++x; // value of y would be 2 That's because the incrementation is done prior to the assignment in the second example, where as it's done after in the first. -
In the first parameter, parentheses () are used to match certain parts of the string, which are stored as back-references for use within the second parameter. These are then retrieved as the $1, $2 and $3 variables. Unlike normal variables though, you don't need to use double-quotes for them to be parsed. FYI you could also use \1, \2, \3. So in this case: (<strong>.*?) = $1 (Paintball Mask) = $2 (.*?<\/strong>) = $3 If there were any more used, they'd carry on into $4, $5, $6, etc. The manual explains all this, I'd recommend having a good read.
-
PLEASE HELP with SQL Query should be simple but missing something!
Adam replied to kamlooper's topic in MySQL Help
You can't have multiple WHERE clauses within a query. How are you running it? If you start an INSERT statement you need to insert some data, otherwise you will get an error. Depending upon the application/environment in which you run it though, you could actually handle the error instead of trying to avoid it. For example, when you try to insert a duplicate row (violating a unique or primary key), you will get a 1062 error. You can capture that error code and display a suitable message instead. -
Simple question, how to make javascript work with mutliple rows?
Adam replied to Jason28's topic in Javascript Help
Ha.. Perhaps ask something "exact"? I would recommend first reading up on how to work with arrays and objects - those are the key to writing these type of scalable functions. It's quite a large subject though for Nightslyr, or anyone to explain it all to you in 'general'. It's the kind of thing you get better at the more experienced you become. -
The forums were upgraded not too long ago, and the solved button hasn't been added back yet.
-
No, though this is a common misconception when learning about database design. Consider how many columns you would actually need to cater for every possible user. Some may speak 1, whilst others may speak 10+. You can't efficiently account for every user with fixed columns. Also, imagine what the query would look like... where language1 = '...' or language2 = '...' or language3 = '...' or language4 = '...' or language5 = '...' -- etc Instead you should take advantage of rows, and more specifically a relational table -- called say `user_languages`. A column in that table would be the foreign key referring to the other table you mentioned -- we'll call it `users` for now. The other column would be the language, though I don't know how you plan to handle languages internally... For example: create table user_languages ( user_id mediumint unsigned not null, language varchar(2) not null, primary key (user_id, language), foreign key (parent_user) references users(id) ) engine=InnoDB; (... This assumes you already have a table called `users` which contains an `id` column.) Now instead of inserting what languages the user speaks into the `users` table, you would insert a row for each language they speak into the `user_languages` table: insert into user_languages (user_id, language) values (1, 'EN'), -- user #1 speaks English (1, 'DE'), -- user #1 also speaks Dutch (1, 'FR'), -- user #1 also speaks French (2, 'EN'); -- user #2 just speaks English Now coming back to how you would query for users matching a language, you just need to join the `user_languages` table, based on the `user_id` where it matches the language: select users.* from users join user_languages on (users.id = user_languages.user_id) where user_languages.language = 'EN'; The database structure above should now allow you to create an interface similar to what you describe, with each text box being a new row in the `user_languages` table.
-
You can use preg_replace() with a single expression for the whole thing: $html = preg_replace('/(<strong>.*?)(Paintball Mask)(.*?<\/strong>)/', '$1<a href="...">$2</a>$3', $html);
-
Help: Refresh parent window by another parent window
Adam replied to paengski13's topic in Javascript Help
So the first page opens the second - "parent" - window? That would automatically mean the second window is a child of the first. Do you mean you need to use the parent object? -
Although you haven't actually said what the problem is, I imagine it's down to the order of operations. You need to use parentheses () to group the calculations, so that you first work out (Motherboard * Quantity), then (Chassis * Quantity), and then add the two. To make things a little more readable you can also store document.calcForm as a variable... function calculate() { var calcForm = document.calcForm; calcForm.total.value = (parseFloat(calcForm.Motherboard.value || 0) * parseFloat(calcForm.Quantity.value || 0)) + (parseFloat(calcForm.Chassis.value || 0) * parseFloat(calcForm.Quantity1.value || 0)) } Notice the additional brackets.
-
Help: Refresh parent window by another parent window
Adam replied to paengski13's topic in Javascript Help
How can you have two parent windows? -
Probably 'undefined', as there's no .value property of a string. jQuery isn't about string operations anyway, it's about "document traversing, event handling, animating, and Ajax interactions". It doesn't replace standard JavaScript objects like Date, Number, String, etc.
-
var a = $("#watermark").val(); var b = $("<?php echo $User['memberID']; ?>").val(); $(..) is a jQuery selector. The top line here passes "#watermark", which is referencing the element with the #ID of "watermark". The method .val() is available because the object that is created has a .value property (.val() also has some more advanced capabilities, but that's for another day). All you need to do is store the value of $User['memberID'] within a normal JavaScript variable: var b = '<?php echo $User['memberID']; ?>';
-
The IP address is safe in terms of SQL injections, however PHP_SELF is not. You can pass an injection through it very easily. As a simple example, consider they inject the URL with /index.php/' OR 1=1 .. that would be preserved within the PHP_SELF variable.
-
That's because on every call to countdown() you're creating another timer, so it will keep running infinitely. You can either create an else clause for your if statement, and move the setTimeout call there - terminating the loop once the name is selected. Or you could use setInterval(), and then clearInterval() once a name is selected.
-
The only way you can do this is if Site A opens Site B in a window with a name.. Site A can then reference that window through window.windowName. Site B can also reference back up to Site A (the parent window) through window.parent.
-
I'm assuming they scammed you? Looking on Google there's countless reviews of people warning that they do that. Did you do any research before signing up with them?
-
Personally I use empty - which implicitly performs an isset check too. Really useful function.
-
Ah, then I think I misunderstood the problem. Looking at your code now actually, you have the colspan assignments commented out: // document.getElementById("carrierMsg1").cells.colspan=8; [...] //document.getElementById("carrierMsg2").cells.colspan=8; Nevermind! Sorted now.
-
I think setAsLastWorkingDay sounds better actually..? Date.prototype.setAsLastWorkingDay = function() {
-
When I first looked at this I thought it was going to be simple, but quickly realised it wasn't with what's available in the JavaScript Date object -- Google weren't much use either. So I decided to write a prototype function that could do it (name needs a bit more thought like): Date.prototype.setAsPrevFridayIfWeekend = function() { // Convert date to previous Friday's if a weekend if (this.getDay() == 0 || this.getDay() == 6) { var move_back = (this.getDay() == 0) ? 2 : 1; if (this.getDate() <= move_back) { if (this.getMonth() == 0) { this.setMonth(11); this.setFullYear(this.getFullYear() - 1); } else { this.setMonth(date.getMonth - 1); } this.setDate(this.getDaysInMonth() - (move_back - this.getDate())); } else { this.setDate((this.getDate() - move_back)); } } } Within this though I had to add another prototype function to work out the number of days in a month, so I borrowed some code from about.com and rewrote it as a prototype function: Date.prototype.getDaysInMonth = function() { var m = [31,28,31,30,31,30,31,31,30,31,30,31]; if (this.getMonth() != 1) return m[this.getMonth()]; if (this.getYear()%4 != 0) return m[1]; if (this.getYear()%100 == 0 && this.getYear()%400 != 0) return m[1]; return m[1] + 1; } So now you can simply include those two prototype functions and call the setAsPrevFridayIfWeekend Date method (as I said the name needs some work), to convert it to the Friday before if it's a weekend. Some test cases (remember months are from 0-11, not 1-12 in JavaScript): window.onload = function() { var date1 = new Date(2011, 0, 1); // Saturday 1st January 2011 date1.setAsPrevFridayIfWeekend(); alert(date1.toString()); // Fri 31st December 2010 var date2 = new Date(2011, 3, 10); // Sunday 10th April 2011 date2.setAsPrevFridayIfWeekend(); alert(date2.toString()); // Fri 8th April 2011 var date3 = new Date(2011, 3, 5); // Tuesday 5th April 2011 date3.setAsPrevFridayIfWeekend(); alert(date3.toString()); // Tuesday 5th April 2011 }
-
I didn't really get the purpose of the IF condition to be honest.
-
That's because you don't have curly braces around the statements within your FOR loop, so what you're effectively doing is: for ($i=0; $i<60; $i++) { if($i>10) { $i = sprintf("%02d",$i); } } echo "<option value=".$i.">" . $i . "</option>"; In which case only the last value of $i (60) will be shown. In PHP you can add curly braces around any block of code even without a control statement, so this is perfectly valid: { echo "<option value=".$i.">" . $i . "</option>"; } And is why your code appeared to be somewhat structured correctly, but in-fact isn't. Try: for ($i=0; $i<60; $i++) { if($i>10) { $i = sprintf("%02d",$i); } echo "<option value=".$i.">" . $i . "</option>"; }
-
Typo in my previous post, should be: "it returns a child object for each cell".
-
You need to pass $i as the second parameter to sprintf().