Hello
A have price data stored like this: 10.25
And percentage data like this 1.1100 (1.00%)
I need a function that accurately multiplies the price by the percentage. (in php)
Thanks
Another potentially interesting (or n00b, whatever comes first) question.
I am building up an array with a set of database fields with information about table, actual field name and descriptive field name as a multi-dimensional array. Here is what it currently looks like:
$Fields['User']['ID'] = "User ID";
$Fields['User']['FirstName'] = "First Name";
$Fields['Stats']['FavouriteOrder'] = "Favourite Item Ordered";
$Fields['Geographic']['Location'] = "Current Location";
$Fields['Geographic']['LocationCode'] = "Current Location Code";
Okay, this is fine, but I am piping this into a system that allows exporting of selected fields, and in the end I want to foreach() through the different levels, extract the data and then ultimately have all the descriptive fields to be displayed sorted alphabetically using their descriptive name. So ultimately in the order: Current Location, Current Location Code, Favourite Item Ordered, First Name then User ID - obviously keeping index associations.
I can't use usort() and I can't use array_multisort()... or maybe I can and I just don't know how. usort() seems to need a key to sort by, but I have variable keys. array_multisort() just seems to do the same as sort() really.
Any ideas?
I think that running this code you will get excactly what I mean. I want to register 5 names to a register(people). I loop 5 times and in each loop I have a variable newPerson which is supposed to save all information about a person and then be added to the people register. In this example only the names of the people are being registered for simplicity.
The problem is that in the end all people turn to have the same name: "Petra". I playied a bit with this but can't get a reasonable reason for this behaviour. Help appreciated!
local people={}
local person={
name="Johan",
lastName="Seferidis",
class="B"
}
local names={"Markus", "Eva", "Nikol", "Adam", "Petra"} --people to register
for i=1, 5 do --register 5 people
local newPerson=person
local name=names[i]
for field=1, 3 do --for each field(name, lastname, class)
if field==1 then newPerson["name"]=name end --register name
end
people[i]=newPerson
end
print("First person name: " ..people[1]["name"])
print("Second person name: "..people[2]["name"])
print("Third person name: " ..people[3]["name"])
I have a table with 2 columns: integer and var char. I am given only the integer values but need to do work on the var char (string) values.
Given an integer, and a list of other integers (no overlap), I want to find the string for that single integer. Then I want to take that string and do the INSTR command with that string, and all the other strings for all the other integers. Then I want the sum of all the INSTR so the result is one number.
So lets say I have int x, and list y=[y0, y1, y2].
I want to do 3 INSTR commands like
SUM(INSTR(string for x, string for y0), INSTR(string for x, string for y1), INSTR(string for x, string for y2))
I think im going in the wrong direction, this is what I have. Im not good with sub queries.
SELECT SUM
(
SELECT INSTR
(
SELECT string FROM pages WHERE int=? LIMIT 1,
(
SELECT string FROM pages WHERE id=? OR id=? OR id=? LIMIT 3
)
)
)
I am trying to display two form submit buttons on the same line inside a table. In IE7 the following code works great, however in IE8 the Delete button drops down to the next line even though I declared the form to display inline. Any suggestions?
I created a basic test page here to show the issue: http://ajondeck.net/test/displayinline.html
I'm able to generate patch files from one version to another using NSIS' Vpatch.
Let's say I have mydll.dll version 1, and I have a patch to update it to version 2. Then I have a new version again, thus I generate another patch to update it to version 3.
What bothers me though is, what if user cancels updating to version 2 and so forth. Then my latest version let's say is version 20. User decides to update to version 20. Is there a way to generate a patch that's like accumulative in nature? whereas user can jump from version any old version to the newest version (i.e ver 3 to ver 20) without passing through the versions in between?
I've read this line in vpatch's documentation --- "if you want to be able to upgrade version 1 and 2 to version 3, you can put a 1 3 and 2 3 patch in one file." But how do I that?
What if I alread have like 30 versions. Does that mean I have to create a patch whose arguments are old files(versions 1-29) and new file(version20)?
Any help would be appreciated. Thanks...
Is there any way to combine all of this to reduce the amount of js? This is just an example of some of the jquery dialogs I have in my site, there are a few more too. Thanks.
//initiate Search refinement dialog here
$("#chooseMoreCnt, #chooseMoreCat, #chooseMorePr").dialog({
bgiframe: true,
autoOpen: false,
width: 500,
modal: true,
open: function(type, data) {
$(this).parent().appendTo(jQuery("form:first"));
}
});
//trigger country dialog
$('a.chooseMoreCnt').click(function() {
$('#chooseMoreCnt').dialog('open');
return false;
});
//trigger category dialog
$('a.chooseMoreCat').click(function() {
$('#chooseMoreCat').dialog('open');
return false;
});
//trigger price dialog
$('a.chooseMorePr').click(function() {
$('#chooseMorePr').dialog('open');
return false;
});
I want to replace every occurrence of the numbers with the string: ???.
Here is an example string:
<em>Chelsea</em> 1-4 Atletico Madrid
How can I do this in JavaScript?
<a href="https://www.google.com/url?sa=t&source=web&cd=9&cad=rja&ved=0CFEQtwIwCA&url=http%3A%2F%2Fwww.whoateallthepies.tv%2Fchelsea%2F137070%2Fsuper-cup-chelsea-1-4-atletico-madrid-falcao-on-fire-as-blues-flop-in-monaco-photos-highlights.html&rct=j&q=chelsea&ei=1odBUImpBIWA0AWM1oC4BA&usg=AFQjCNEwdCCckt15XTkHSAf2fsUnGk9IJg&sig2=IOrD6hfMrviW9ods0DG2dw" class="l" onmousedown="return rwt(this,'','0','','9','AFQjCNEwdCCckt15XTkHSAf2fsUnGk9IJg','IOrD6hfMrviW9ods0DG2dw','0CFEQtwIwCA',null,event)" title="Super Cup: Chelsea 1-4 Atletico Madrid – Falcao On Fire As Blues Flop In Monaco (Photos ...">Super Cup: <em>Chelsea</em> 1-4 Atletico Madrid – Falcao On <b>...</b></a>
Thanks in advance.
I would like to create a view similar to the "Now Playing" page on the iPhone and have 3 lines of text in the Navigation bar.
The only way I could find to do this was:
UINavigationBar *bar = [self.navigationController navigationBar];
label = [[UILabel alloc] initWithFrame:CGRectMake(60, 2, 200, 14)];
label.tag = SONG_TAG;
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont boldSystemFontOfSize:14];
label.adjustsFontSizeToFitWidth = NO;
label.textAlignment = UITextAlignmentCenter;
label.textColor = [UIColor whiteColor];
label.highlightedTextColor = [UIColor blackColor];
[bar addSubview:label];
[label release];
//Create album label
label = [[UILabel alloc] initWithFrame:CGRectMake(60, 17, 200, 12)];
label.tag = ALBUM_TAG;
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont systemFontOfSize:12];
label.adjustsFontSizeToFitWidth = NO;
label.textAlignment = UITextAlignmentCenter;
label.highlightedTextColor = [UIColor blackColor];
label.textColor = HEXCOLOR(0xA5A5A5ff);
[bar addSubview:label];
[label release];
//Create artist label
label = [[UILabel alloc] initWithFrame:CGRectMake(60, 30, 200, 12)];
label.tag = ARTIST_TAG;
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont systemFontOfSize:12];
label.adjustsFontSizeToFitWidth = NO;
label.textAlignment = UITextAlignmentCenter;
label.highlightedTextColor = [UIColor blackColor];
label.textColor = HEXCOLOR(0xA5A5A5ff);
[bar addSubview:label];
[label release];
The problem with this is I have to remove them when the view changes. So, in -viewWillDisappear I have:
UILabel *label;
label = (UILabel *)[self.navigationController.navigationBar viewWithTag:SONG_TAG];
[label removeFromSuperview];
label = (UILabel *)[self.navigationController.navigationBar viewWithTag:ALBUM_TAG];
[label removeFromSuperview];
label = (UILabel *)[self.navigationController.navigationBar viewWithTag:ARTIST_TAG];
[label removeFromSuperview];
I think the way to do this is make a custom view that has the 3 labels in it, and add this to the title view. (here's the catch - you can only add 1 label or view to the title view spot on the nav bar)
self.navigationItem.titleView = newViewIMadeWithThreeLabels
I want to change the numbers in my dictionary to int values for use later in my program.
So far I have
import time
import math
x = 400
y = 300
def read_next_object(file):
obj = {}
for line in file:
if not line.strip(): continue
line = line.strip()
key, val = line.split(": ")
if key in obj and key == "Object":
yield obj
obj = {}
obj[key] = val
yield obj
planets = {}
with open( "smallsolar.txt", 'r') as f:
for obj in read_next_object(f):
planets[obj["Object"]] = obj
print(planets)
scale=250/int(max([planets[x]["Orbital Radius"] for x in planets if "Orbital Radius" in planets[x]]))
print(scale)
and the output is
{'Sun': {'Object': 'Sun', 'Satellites': 'Mercury,Venus,Earth,Mars,Jupiter,Saturn,Uranus,Neptune,Ceres,Pluto,Haumea,Makemake,Eris', 'Orbital Radius': '0', 'RootObject': 'Sun', 'Radius': '20890260'}, 'Moon': {'Object': 'Moon', 'Orbital Radius': '18128500', 'Period': '27.321582', 'Radius': '1737000.10'}, 'Earth': {'Object': 'Earth', 'Satellites': 'Moon', 'Orbital Radius': '77098290', 'Period': '365.256363004', 'Radius': '6371000.0'}}
3.2426140709476178e-06
I want to be able to convert the numbers in the dict to ints for further use. Any help in greatly appreciated.
Hello
I'm creating a website with structure like this:
class main { }
class mysql extends main { }
class user extends main { }
class etc extends main { }
The idea is for these classes to use functions from each other. This doesn't work. How can I call a function from mysql in user?
Martti Laine
There might be a really simple solution to this question, but i just don't see it!
I have a page with a list of items. every item has the same jquery ui button (its inside a dialog and adds that item to a list). i identify the item via the parenting DIV holding the DB id. So far so good...
The Problem is only the first button on the list works! The second, third etc. buttons don't show any reaction at all. The buttons all have the same id - as the list is dynamic and the same action is triggered with every click. Only the parenting ID changes.
Heres the display part:
<div id="2">
<div id="56">
<button id="add-audio-file" class="ui-button ui-state-default ui-corner-all">betty_2.mp3</button>
</div>
</div>
<div id="2">
<div id="57">
<button id="add-audio-file" class="ui-button ui-state-default ui-corner-all">betty_3.mp3</button>
</div>
</div>
And here comes the js Part:
$('#add-audio-file').click(function() {
assetID = $(this).parent('div').attr('id');
pageID = $(this).parent('div').parent('div').attr('id');
$.post(
"modules/portfolio/serialize.php",
{id : pageID, assetid : assetID, do : "add-audio-file"},
function(data, textStatus, xhr) {
$('#dialog-add-audio').dialog('close');
}
);
});
I am using jquery 1.4.2 and jquery ui 1.8rc3
Any ideas?
I have a form where users can add input fields with jQuery.
<input type="text" id="task" name="task[]" />
After submitting the form I get an array on PHP.
I want to handle this with the $.ajax() but I have no idea how to turn my <input>s to an array in jQuery.
Thanks in advance.
I have a dozen servers in different locations all running the same web service application but each going against their own SQL Server DB. I am writing a desktop application that consumes the web services. I want to present the user with a drop down of all servers in the network that are running the same wweb service application. Do I have to add a ServiceReference for each of the servers running the web service app and thereby having as many proxies as there are servers? Or can a define a single instance of the services and dynamically build a list of endpoints to select from a drop down?
Hi, I'm new to PHP oop stuff.
I'm trying to create class database and call other classes from it. Am I doing it the right way?
class database:
class database extends mysqli {
private $classes = array();
public function __construct() {
parent::__construct('localhost', 'root', 'password', 'database');
if (mysqli_connect_error()) {
$this->error(mysqli_connect_errno(), mysqli_connect_error());
}
}
public function __call($class, $args) {
if (!isset($this->classes[$class])) {
$class = 'db_'.$class;
$this->classes[$class] = new $class();
}
return $this->classes[$class];
}
private function error($eNo, $eMsg) {
die ('MySQL error: ('.$eNo.': '.$eMsg);
}
}
class db_users:
class db_users extends database {
public function test() {
echo 'foo';
}
}
and how I'm using it
$db = new database();
$db->users()->test();
Is it the right way or should it be done another way?
Thank you.
I have 3 UITextFields in a grouped UITableView and am trying to figure out the correct logic to only have my 'Save' UIBarButtonItem enabled when none of the UITextFields are empty.
I'm currently using the - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string UITextField delegate method to detect changes to the field character by character, but it is providing inconsistent results.
Any ideas?
Hello,
Could anyone point exactly where MSDN says thet every user stored procedure returns 0 by default if no error happens? In other words, could I be sure that example code given below when being a stored procedure
IF someStatement
BEGIN
RETURN 1
END
should always return zero if someStatement is false and no error occurs?
I know that it actually works this way, but I failed to find any explicit statement about this from Microsoft.
well i like this nice of code right here it seems to work awsome but i cant seem to add any more directories to it
{
DirectoryInfo dir = new DirectoryInfo(@"C:\temp");
foreach(FileInfo files in dir.GetFiles())
{
files.Delete();
}
foreach (DirectoryInfo dirs in dir.GetDirectories())
{
dirs.Delete(true);
}
}
i would also like to add in special folders aswell like History and cookies and such how would i go about doing that (i would like to include atleast 4-5 different folders)
Suppose you have the following schema (id, user_id , score). How can I take per each user the row with max score and then order all row for score. In other word I want a ranking where each user have his best result.
I'm using the Active Directory Membership Provider with the following configuration:
<connectionStrings>
<add name="MyConnString" connectionString="LDAP://domaincontroller/OU=Product Users,DC=my,DC=domain,DC=com" />
</connectionStrings>
<membership defaultProvider="MyProvider">
<providers>
<clear />
<add name="MyProvider" connectionStringName="MyConnString"
connectionUsername="my.domain.com\service_account"
connectionPassword="biguglypassword"
type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</providers>
</membership>
This works perfectly except it requires ALL of my users to be in the "Product Users" OU when I would actually like to have all of my users organized into various child OUs under our "Product Users" OU. Is this possible?
(Note that this is a partial repost of this question but the question I'm asking here was never answered there.)
I have been searching for a solution to this for a while and have not found quite what I need.
I have several Git Repositories in a folder on my Mac (OSX 10.6) and would like a script or tool that will loop through all the repositories and let me know if any of them needs "commit"-ing.
This is my structure
Sites
/project1
/project2
/project3
I want the tool to do a "git status" in Sites/project1, Sites/project2, Sites/project3 and let me know if Sites/project2 and Sites/project3 have changes or new files and needs to be Staged/committed
The closest script I found that might be hackable is here:
http://gist.github.com/371828
but even that script wouldn't run and I get an error:
"syntax error near unexpected token `do"
which might have been written for *nix.
Can any one please let me know the best way to use IF statement in mysql query to show if the "email" field is NULL then it should show as "no email"...
Postcode Telephone Email
----------------------------------------------------------
BS20 0QN 1275373088 no email
BS20 0QN 1275373088 no email
PO9 4HG 023 92474208 [email protected]
SO43 7DS 07801 715200 [email protected]
----------------------------------------------------------
Hi all,
I have a Webapp which connects to 2 DBs (one core, the other is a logging DB).
I must now create a Windows service which will use the same business logic/Data access DLLs. However when I try to reference 2 session factories in the Service App and call the factory.GetCurrentSession() method, I get the error message "No session bound to current context".
Does anyone have a suggestion about how this can be done?
public class StaticSessionManager
{
public static readonly ISessionFactory SessionFactory;
public static readonly ISessionFactory LoggingSessionFactory;
static StaticSessionManager()
{
string fileName = System.Configuration.ConfigurationSettings.AppSettings["DefaultNHihbernateConfigFile"];
string executingPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
fileName = executingPath + "\\" + fileName;
SessionFactory = cfg.Configure(fileName).BuildSessionFactory();
cfg = new Configuration();
fileName = System.Configuration.ConfigurationSettings.AppSettings["LoggingNHihbernateConfigFile"];
fileName = executingPath + "\\" + fileName;
LoggingSessionFactory = cfg.Configure(fileName).BuildSessionFactory();
}
}
The configuration file has the setting:
<property name="current_session_context_class">call</property>
The service sets up the factories:
private ISession _session = null;
private ISession _loggingSession = null;
private ISessionFactory _sessionFactory = StaticSessionManager.SessionFactory;
private ISessionFactory _loggingSessionFactory = StaticSessionManager.LoggingSessionFactory;
...
_sessionFactory = StaticSessionManager.SessionFactory;
_loggingSessionFactory = StaticSessionManager.LoggingSessionFactory;
_session = _sessionFactory.OpenSession();
NHibernate.Context.CurrentSessionContext.Bind(_session);
_loggingSession = _loggingSessionFactory.OpenSession();
NHibernate.Context.CurrentSessionContext.Bind(_loggingSession);
So finally, I try to call the correct factory by:
ISession session = StaticSessionManager.SessionFactory.GetCurrentSession();
Can anyone suggest a better way to handle this?
Thanks in advance!
Rob