Saturday, April 4, 2009

SQL Left Join Twice

Say if you have two category id for a logo {logoId, logoCode }, and the category {catId,catDescription} belongs to another table with a link on table {catId, logoId} we need to left join on each logo twice, so that we can get the logo category as a single row. The SQL is as follows:

SELECT `categoryLinksId`, `_category`.`catId` as `pcatId`, `_category`.`catName` as `pcatName`, `category1`.`catId` as `ccatId`, `category1`.`catName` as `ccatName` FROM (`_categorylinks` LEFT JOIN `_category` ON `_categorylinks`.`parent_categoryId` = `_category`.`catId`) LEFT JOIN `_category` as `category1` ON `_categorylinks`.`child_categoryId` = `category1`.`catId`

Update parent body from child popup

This script is typically full of bugs due to the difference in the way Javascript is being processed in Internet Explorer or Firefox. Fundamentally, the difference is in the way Internet explorer does chaining (its more intelligent) as compared to that of Firefox. But then again, Firefox forces you to write good codes. What normally works in Firefox will work in Internet Explorer, but not neccessarily the other way round.

Anyhow, the codes for the parent window is as follows:
<script type="text/javascript">
<!--
// What these codes does it open up a popup when you click on something and when we receive a signal from the child, we updateLayer
function openBrWindow(theURL,winName,features) {
(theURL,winName,features);
}
function updateLayer() {

var obj = document.getElementById('selectcat1');
obj.innerHTML = "Testing"; // I had to do it this way else Firefox won't accept it!
}
//-->

</script>
You can open a new window with the following:

<a onclick="openBrWindow('selectcat.php','selectcat1','location=0,scrollbars=1,width=700,height=300')" href="#">popup</a>
The thing to update in parent is a SPAN Tag:
<span id="selectcat1" class="greyFont">None</span>


The codes for the child popup window is:
<script type="text/javascript">
<!-- function updateParentCloseSelf() {

opener.updateLayer();
self.close();
}
//-->
</script>

The button within the child is:

<input onclick="javascript:updateParentCloseSelf();" border="0" value="Submit Query" type="submit" name="Submit">

Wednesday, April 1, 2009

Accurately Position Drag and Drop Item

Anyone who played with Flex' drag and drop function (for canvas) will know that the drag and drop function will cause the image to be incorrectly placed on a canvas. That is, the background transparent image will appear on this particular position (when you hold down your mouse button) but when you release your mouse, the image appears in another position that is not accurately where you dropped it.

This is due to the fact that the image (when you clicked) had a pointer that was not at coordinates zero, zero. When we click the image and drag, it was most likely at a portion of the image, and when we drag it around the canvas, the 'transparent rectangular background of the image' made it appear as if we are dropping the image at that particular rectangular position.

You can see the codes to do drag and drop for canvas at:
http://livedocs.adobe.com/flex/3/html/help.html?content=dragdrop_7.html

In order to overcome this problem, at line dragInitiator, i added the following lines:
ds.addData(event.localX, "NumberX");
ds.addData(event.localY, "NumberY");

Then at the line of dragDropHandler, I placed the following:
Image(event.dragInitiator).x =
Canvas(event.currentTarget).mouseX- parseInt("" + event.dragSource.dataForFormat("NumberX"));
Image(event.dragInitiator).y =
Canvas(event.currentTarget).mouseY- parseInt("" + event.dragSource.dataForFormat("NumberY"));

Viola! Your image should appear wherever you drop them now.

Monday, March 30, 2009

Fatal error: Cannot use object of type stdClass as array...

While programming, I was stuck in this bug.
Fatal error: Cannot use object of type stdClass as array in C:\xampp\htdocs\redtaglogo2\members\temp3.php on line 24

I immediately check the var_dump output of the array and I got:
array(3) { [1]=> object(stdClass)#14 (6) { ["id"]=> string(1) "1" ["parent_id"]=> string(1) "0" ["title"]=> string(8) "Artistic" ["nleft"]=> string(1) "1" ["nright"]=> string(2) "28" ["nlevel"]=> string(1) "1" } [5]=> object(stdClass)#13 (6) { ["id"]=> string(1) "5" ["parent_id"]=> string(1) "1" ["title"]=> string(7) "Objects" ["nleft"]=> string(2) "20" ["nright"]=> string(2) "27" ["nlevel"]=> string(1) "2" } [6]=> object(stdClass)#12 (6) { ["id"]=> string(1) "6" ["parent_id"]=> string(1) "5" ["title"]=> string(6) "People" ["nleft"]=> string(2) "23" ["nright"]=> string(2) "24" ["nlevel"]=> string(1) "3" } }

Which looks correct and I have something for my array. The code that was producing the error was:
for ($i=0; $i <>
echo $path[$i][0];
}

I then tried to get it like an object:
for ($i=0; $i < sizeof($path); $i++) {
echo $path[$i]->title;
}

It returned me the wrong results!

I finally solved the problem using foreach:
foreach ($path as $stdObject) {
echo $stdObject->title . "
";
}


Viola

Friday, February 27, 2009

Error on git-warning

While I was executing a gui program from the console, I got the following error:

Application initialization failed: couldn't connect to display "0:0"
Error in startup script: invalid command name "mc"
while executing
"mc "git-gui: fatal error""
invoked from within
"if {[catch {package require Tcl 8.4} err]
|| [catch {package require Tk 8.4} err]
} {
catch {wm withdraw .}
tk_messageBox \
-icon error \
-typ..."
(file "/usr/bin/git-gui" line 34)

The problem turn out to be the fact that I am not in the sudoers list.

Friday, February 6, 2009

Unable to view Flex program in Firefox and Safari

If you have a Flex program, but you are unable to run it successfully in Firefox and Safari but you can run it inside internet explorer, then chances are you are having some problems with the javascript component that loads the flex program.

It may not be a flex program error, look in the javascript first.

Looking for content within files in Linux

Within your directory, type the following command:

sudo find . -print xargs grep "pattern to search for"

or if you have the name type, you can try

sudo find . -name "*.pl" xargs grep "pattern to search for"