How to count the number of occurrences of an ID from a different table
I'm making an access database on UFC fights. I have a fightschedule table
that has the IDs of each fighter for each fight and the winner of the
fights. I'm trying to make a query that lists every fighter that fought
and lists how many wins each one had.
This is an example of my fightSchedule table
ID Fighter1 Fighter2 Weight Class Date Winner
A 205 215 Light Heavyweight 8/14/2013 205
B 206 212 Welterweight 8/15/2013 212
C 207 218 Middleweight 8/14/2013 207
D 208 209 Heavyweight 8/14/2013 209
So for for example I want a query that would look something like this:
Fighter # of Wins
205 1
206 0
207 1
208 0
209 1
212 1
215 0
218 0
I don't know much about what would go into doing this at all. I know how
to use the count function but no idea how to use it like I want in this
example.
I found this on W3 Schools but I don't know if this is the right one to
use or how to use it.
SELECT column_name, COUNT(column_name)
FROM table_name
GROUP BY column_name
Any help would be appreciated. Thank you!
Saturday, 31 August 2013
Url Detection using Jscript
Url Detection using Jscript
This is the javascrip that i have implemented for url detection in a plain
text but when i am clicking on the link i am not able to open the link in
new tab it is opening the localhost address before the website.
Example : i have detected www.google.com
when i am clicking on it i am getting this
(localhost:3415/Home/www.google.com)
i want only www.google.com to be open in new tab
<-- Code -->
<script type="text/javascript">
function test() {
dt(document.getElementById('d').value);
}
function dt(t) {
// find links wo www and http. bla.bla.TLD(ANY query)
var srg = new
RegExp(/(^|\b)([\w.]+\.[a-z]{2,3}(?:\:[0-9]{1,5})?(?:\/.*)?)([,\s]|$)/ig);
var r = t.replace(srg, '$1<a href="$2" target="_blank">$2</a>');
document.getElementById('c').innerHTML = r;
}
</script>
This is the javascrip that i have implemented for url detection in a plain
text but when i am clicking on the link i am not able to open the link in
new tab it is opening the localhost address before the website.
Example : i have detected www.google.com
when i am clicking on it i am getting this
(localhost:3415/Home/www.google.com)
i want only www.google.com to be open in new tab
<-- Code -->
<script type="text/javascript">
function test() {
dt(document.getElementById('d').value);
}
function dt(t) {
// find links wo www and http. bla.bla.TLD(ANY query)
var srg = new
RegExp(/(^|\b)([\w.]+\.[a-z]{2,3}(?:\:[0-9]{1,5})?(?:\/.*)?)([,\s]|$)/ig);
var r = t.replace(srg, '$1<a href="$2" target="_blank">$2</a>');
document.getElementById('c').innerHTML = r;
}
</script>
Where am I getting wrong in the destructor for this C++ container?
Where am I getting wrong in the destructor for this C++ container?
I am dealing with a map, whose second element is also a map, whose second
element is a vector. And during the map building process it seems I have
to allocate the memory dynamically, but then I fail to release the memory
properly. My problem can be reduced to the source code below.
I just cannot figure out why the desctructor is incorrect.
Also, is there any better way to avoid memory leak in this case?
#include <vector>
#include <map>
#include <iostream>
using namespace std;
typedef vector<int> IntVect;
typedef map<int, IntVect> NumEle;
typedef map<int, NumEle> Nums;
class NumLess {
public:
Nums numSet;
~NumLess() {
for (Nums::iterator I = numSet.begin(), E = numSet.end(); I != E; ++I) {
NumEle &numEle = I->second;
for (NumEle::iterator II = numEle.begin(), EE = numEle.end(); II !=
EE; ++II) {
IntVect &intVect = II->second;
intVect.clear();
delete &intVect;
}
delete &numEle;
}
}
friend ostream &operator<<(ostream &os, const NumLess &numLess) {
for (Nums::const_iterator I = numLess.numSet.begin(),
E = numLess.numSet.end();
I != E; ++I) {
const NumEle &numEle = I->second;
os << "NumEle:" << I->first << endl;
for (NumEle::const_iterator II = numEle.begin(), EE = numEle.end();
II != EE; ++II) {
os << "IntVect " << II->first << " | ";
const IntVect &intVect = II->second;
for (auto i : intVect) {
os << i << " ";
}
os << endl;
}
}
return os;
}
};
int main(void) {
NumLess numLess;
for (unsigned h = 4; h > 0; --h) {
NumEle *numEle = new NumEle();
for (unsigned i = h; i > 0; --i) {
IntVect *intVect = new IntVect();
for (unsigned j = 0; j < i; ++j) {
intVect->push_back(j);
}
numEle->insert(pair<int, IntVect>(i, *intVect));
}
numLess.numSet.insert(pair<int, NumEle>(h, *numEle));
}
cout << numLess;
cout << "finished" << endl;
return 0;
}
I am dealing with a map, whose second element is also a map, whose second
element is a vector. And during the map building process it seems I have
to allocate the memory dynamically, but then I fail to release the memory
properly. My problem can be reduced to the source code below.
I just cannot figure out why the desctructor is incorrect.
Also, is there any better way to avoid memory leak in this case?
#include <vector>
#include <map>
#include <iostream>
using namespace std;
typedef vector<int> IntVect;
typedef map<int, IntVect> NumEle;
typedef map<int, NumEle> Nums;
class NumLess {
public:
Nums numSet;
~NumLess() {
for (Nums::iterator I = numSet.begin(), E = numSet.end(); I != E; ++I) {
NumEle &numEle = I->second;
for (NumEle::iterator II = numEle.begin(), EE = numEle.end(); II !=
EE; ++II) {
IntVect &intVect = II->second;
intVect.clear();
delete &intVect;
}
delete &numEle;
}
}
friend ostream &operator<<(ostream &os, const NumLess &numLess) {
for (Nums::const_iterator I = numLess.numSet.begin(),
E = numLess.numSet.end();
I != E; ++I) {
const NumEle &numEle = I->second;
os << "NumEle:" << I->first << endl;
for (NumEle::const_iterator II = numEle.begin(), EE = numEle.end();
II != EE; ++II) {
os << "IntVect " << II->first << " | ";
const IntVect &intVect = II->second;
for (auto i : intVect) {
os << i << " ";
}
os << endl;
}
}
return os;
}
};
int main(void) {
NumLess numLess;
for (unsigned h = 4; h > 0; --h) {
NumEle *numEle = new NumEle();
for (unsigned i = h; i > 0; --i) {
IntVect *intVect = new IntVect();
for (unsigned j = 0; j < i; ++j) {
intVect->push_back(j);
}
numEle->insert(pair<int, IntVect>(i, *intVect));
}
numLess.numSet.insert(pair<int, NumEle>(h, *numEle));
}
cout << numLess;
cout << "finished" << endl;
return 0;
}
fork(), problems with multiple children
fork(), problems with multiple children
1st, the code :
//create child
for ( ii = 0; ii < nbEnfants; ++ii) {
if ((p = fork()) == 0) {
/** PROCESSUS CHILD here **/
EEcrireMp(ii);
//exit(0);
}
else {
/** PROCESSUS PARENT here **/
tabPidEnfants[ii] = p;
usleep(50000);
ELireMp(nbSect, nbEnfants);
}
}
What I want to do : Create only 20 child records then do the thing in the
"else".This code works only if I leave the "exit()" but I can't leave it
because I won't have anymore "concurency" and I need "concurency" :/ In
"EEcrireMp()", I use semaphore (initialized at 0), so I do +1 each time
this function is run(it writes in shared_memory). Then if the same value
is equal to 20, then the condition in the "ELireMp()" will be activated,
and I can read what the 20 children writes. So like I said, this works
only if the "exit()" is there. If I remove the "exit()", I have the
impression that my child creates another 20 child and one off the new
child creates himself other 20 child and etc ... :( ps : my computer
completely freezes if I run the program. Thanks
1st, the code :
//create child
for ( ii = 0; ii < nbEnfants; ++ii) {
if ((p = fork()) == 0) {
/** PROCESSUS CHILD here **/
EEcrireMp(ii);
//exit(0);
}
else {
/** PROCESSUS PARENT here **/
tabPidEnfants[ii] = p;
usleep(50000);
ELireMp(nbSect, nbEnfants);
}
}
What I want to do : Create only 20 child records then do the thing in the
"else".This code works only if I leave the "exit()" but I can't leave it
because I won't have anymore "concurency" and I need "concurency" :/ In
"EEcrireMp()", I use semaphore (initialized at 0), so I do +1 each time
this function is run(it writes in shared_memory). Then if the same value
is equal to 20, then the condition in the "ELireMp()" will be activated,
and I can read what the 20 children writes. So like I said, this works
only if the "exit()" is there. If I remove the "exit()", I have the
impression that my child creates another 20 child and one off the new
child creates himself other 20 child and etc ... :( ps : my computer
completely freezes if I run the program. Thanks
Get the key value of the row of whose cusstom button has been clicked
Get the key value of the row of whose cusstom button has been clicked
I found myself in need of what i guess should be a trivial requirement. i
have a jqGrid in which i have added a custom button in each row. now i am
able to associate a client side click event with it but i want to know the
key value (Id) in my case of the row whose custom button was clicked, so
that i can proceed with this id and do whatever i want to do.
My code for jqGrid is as below
jQuery("#JQGrid").jqGrid({
url: 'http://localhost:55423/JQGrid/JQGridHandler.ashx',
datatype: "json",
colNames: ['', 'Id', 'First Name', 'Created Date', 'Member Price',
'Non Member Price', 'Complete', 'customButton'],
colModel: [
{ name: '', index: '', width: 20, formatter:
"checkbox", formatoptions: { disabled: false} },
{ name: 'Id', index: 'Id', width: 20, stype: 'text',
sortable: true, key: true },
{ name: 'FirstName', index: 'FirstName', width: 120,
stype: 'text', sortable: true },
{ name: 'CreatedDate', index: 'CreatedDate', width:
120, editable: true, sortable: true, hidden: true,
editrules: { edithidden: true} },
{ name: 'MemberPrice', index: 'MemberPrice', width:
120, editable: true, sortable: true },
{ name: 'NonMemberPrice', index: 'NonMemberPrice',
width: 120, align: "right", editable: true, sortable:
true },
{ name: 'Complete', index: 'Complete', width: 60,
align: "right", editable: true, sortable: true },
{ name: 'customButton', index: 'customButton', width:
60, align: "right" }
],
rowNum: 10,
loadonce: true,
rowList: [10, 20, 30],
pager: '#jQGridPager',
sortname: 'Id',
viewrecords: true,
sortorder: 'desc',
caption: "List Event Details",
gridComplete: function () {
jQuery(".jqgrow td input", "#JQGrid").click(function () {
//alert(options.rowId);
alert("Capture this event as required");
});
}
});
jQuery('#JQGrid').jqGrid('navGrid', '#jQGridPager',
{
edit: true,
add: true,
del: true,
search: true,
searchtext: "Search",
addtext: "Add",
edittext: "Edit",
deltext:"Delete"
},
{/*EDIT EVENTS AND PROPERTIES GOES HERE*/ },
{/*ADD EVENTS AND PROPERTIES GOES HERE*/},
{/*DELETE EVENTS AND PROPERTIES GOES HERE*/},
{/*SEARCH EVENTS AND PROPERTIES GOES HERE*/}
);
Help or any pointers would be much appreciated.
I found myself in need of what i guess should be a trivial requirement. i
have a jqGrid in which i have added a custom button in each row. now i am
able to associate a client side click event with it but i want to know the
key value (Id) in my case of the row whose custom button was clicked, so
that i can proceed with this id and do whatever i want to do.
My code for jqGrid is as below
jQuery("#JQGrid").jqGrid({
url: 'http://localhost:55423/JQGrid/JQGridHandler.ashx',
datatype: "json",
colNames: ['', 'Id', 'First Name', 'Created Date', 'Member Price',
'Non Member Price', 'Complete', 'customButton'],
colModel: [
{ name: '', index: '', width: 20, formatter:
"checkbox", formatoptions: { disabled: false} },
{ name: 'Id', index: 'Id', width: 20, stype: 'text',
sortable: true, key: true },
{ name: 'FirstName', index: 'FirstName', width: 120,
stype: 'text', sortable: true },
{ name: 'CreatedDate', index: 'CreatedDate', width:
120, editable: true, sortable: true, hidden: true,
editrules: { edithidden: true} },
{ name: 'MemberPrice', index: 'MemberPrice', width:
120, editable: true, sortable: true },
{ name: 'NonMemberPrice', index: 'NonMemberPrice',
width: 120, align: "right", editable: true, sortable:
true },
{ name: 'Complete', index: 'Complete', width: 60,
align: "right", editable: true, sortable: true },
{ name: 'customButton', index: 'customButton', width:
60, align: "right" }
],
rowNum: 10,
loadonce: true,
rowList: [10, 20, 30],
pager: '#jQGridPager',
sortname: 'Id',
viewrecords: true,
sortorder: 'desc',
caption: "List Event Details",
gridComplete: function () {
jQuery(".jqgrow td input", "#JQGrid").click(function () {
//alert(options.rowId);
alert("Capture this event as required");
});
}
});
jQuery('#JQGrid').jqGrid('navGrid', '#jQGridPager',
{
edit: true,
add: true,
del: true,
search: true,
searchtext: "Search",
addtext: "Add",
edittext: "Edit",
deltext:"Delete"
},
{/*EDIT EVENTS AND PROPERTIES GOES HERE*/ },
{/*ADD EVENTS AND PROPERTIES GOES HERE*/},
{/*DELETE EVENTS AND PROPERTIES GOES HERE*/},
{/*SEARCH EVENTS AND PROPERTIES GOES HERE*/}
);
Help or any pointers would be much appreciated.
Friday, 30 August 2013
How do I search for documentation on numerical macros?
How do I search for documentation on numerical macros?
I know there are objective-c (or C) macros for quantities like maximum
integer, max float, max unsigned integer, etc. but every time I need to
use one I can't remember it and I can't find it by searching. How do you
search for those things?
I know there are objective-c (or C) macros for quantities like maximum
integer, max float, max unsigned integer, etc. but every time I need to
use one I can't remember it and I can't find it by searching. How do you
search for those things?
Thursday, 29 August 2013
Xpath query assistance nested anchor href extract
Xpath query assistance nested anchor href extract
Here is my code:
$text = '<div class="cgus_post"><a href="?p=15055">Hello</a></div>';
$dom = new DomDocument();
$dom->loadHTML($text);
$classname = 'cgus_post';
$finder = new DomXPath($dom);
$nodes = $finder->query('//div[class="cgus_post"]//@href');
I'm trying to get the href text for an anchor link within the div
cgus_post. What's wrong with my query?
Here is my code:
$text = '<div class="cgus_post"><a href="?p=15055">Hello</a></div>';
$dom = new DomDocument();
$dom->loadHTML($text);
$classname = 'cgus_post';
$finder = new DomXPath($dom);
$nodes = $finder->query('//div[class="cgus_post"]//@href');
I'm trying to get the href text for an anchor link within the div
cgus_post. What's wrong with my query?
Subscribe to:
Posts (Atom)