quarta-feira, novembro 30, 2005

Using Javascript OnChange() with php.

I'm sure that all php developers who writes more than "Hello World" code, have found themselves needing to feed a combo box when the user select something in another combo box. Like when you select your state, the page fill the cities combo box with all the cities from that state.

Again, my best friend Google helped me and I found an easy solution.

The solution was found in the Zazzybob.com website, and here's the PDF and the HTML with the solution for this problem.

As I'm bored, I'll give you a preview of the code that is in the pdf, see below:

Here is the javascript code, as you can see, you can post the form to one page with the onchange() and can post the page to another page when you click in the submit button, so here we go:

Javascript functions:

function resubmit() {
document.form_name.action="some_page.php";
document.form_name.submit();
}
function process() {
document.form_name.action="another_page.php";
document.form_name.submit();
}

Remember that you have to change the form_name to whatever you name your form.

And now the html stuff:
<select name="state" onchange="resubmit();">

<input type="submit" name="sub_form" value="Submit!" onclick="process();">

Now you are asking, where the hell is the php on it?

In this example, you just need to query your database or use any other method to populate the cities combo box, something like this:

<?
if($_POST['state']) {
$id = $_POST['state'];
$sql = "SELECT city_id, city_name FROM cities WHERE state='$id'";
...
}
?>

Remember that this is just an example, don't try using this code, you will regret it :)

For a more detailed explanation, please read the PDF.

segunda-feira, novembro 28, 2005

Install Thunar file manager on Xubuntu

I tried Xubuntu here and it was love at first sight, but the only thing that i disliked about it was the rox-filer, not that its not good, its very fast, but for some reasons i think its too complicated, and i missed some nautilus features.

The purpose of this thread is to help you install Thunar from svn, its far easier than rox and looks like nautilus, so you will be at home.

Thunar is still in early development stage, so dont expect too much from it, but it can do the basic stuff, open, copy, move, delete files, etc.

For more info and screenshots, click here.

Here a screenshot:

Free Image Hosting at www.ImageShack.us



Btw.. lets start.


To install xfce (Xubuntu) in breezy is simple:

sudo apt-get install xubuntu-desktop


To enter xfce just logoff from your Gnome or KDE Session, click on the session button and choose XFCE.

Now to install Thunar, open up a terminal and cut and paste, or type the following commands:


sudo apt-get install gtk-doc-tools libxml-parser-perl automake1.8 libxfce4util-dev

svn co http://svn.xfce.org/svn/xfce/libexo/trunk xfce4-svn-source/libexo
svn co http://svn.xfce.org/svn/xfce/thunar/trunk xfce4-svn-source/thunar
svn co http://svn.xfce.org/svn/xfce/xfce4-dev-tools/trunk xfce4-svn-source/xfce4-dev-tools

cd xfce4-svn-source/xfce4-dev-tools
sh autogen.sh
make
sudo make install

cd ../libexo/
sh autogen.sh
make
sudo make install

cd ../thunar/
sh autogen.sh
make
sudo make install


Now to open up tunar, just create a shortcut to it, right click on the xfce panel, add new item, then select laucher, select an icon, and in the command fill with thunar.

If you have some more tips about it, or any doubs please ask, so i can update the howto and make it better.

For now is just it, i just wanted to share it with all the ubuntu users, if you have a slow pc or if you would like to make you fast pc fly, give Xubuntu a try.

domingo, novembro 27, 2005

In love With Xubuntu

I m going to install Ubuntu in a 400mhz pc this monday, finally convinced my boss that i would work better if i was in linux.

So i read about Xubuntu and decided to try it out at my home pc (A64 2800+, 512MB RAM).

And now i m in love with it, good bye Ubuntu (Gnome), welcome Xubuntu (xfce).

My first impressions couldnt be better.

1 - I really loved the blue boot up screen.
2 - It flies man, i cant believe how fast my computer is running
3 - I thought it was kinda of a "ripped" desktop without anything, but i was wrong, it has almost everything i had in gnome.
4 - I love being able to drag my windows to another desktop and go to another desktop draging the mouse to the edge of the screen.
5 - The control panel rules, its perfect, in the screenshot below you can see it, it changed my resolution without restarting X, and its very easy and intuitive to use.

But i disliked some stuffs, nothing serius...

1 - I couldnt make the main panel fill the screen width
2 - RoX-filer is too simple, its as fast as the speed of light, but it doesnt have tree view, doesnt have video thumbnails, and i cant move files with ctrl + X, ctrl + X is used to delete a file.
3 - It doesnt have icons, nor any options on the desktop, like right clicking in the wallpaper.

I just cant wait to see the Xubuntu cd that are coming with the Dapper Drake release.

More info about Xubuntu can be found HERE.

Here a screenshot of how my desktop looks like now:

Free Image Hosting at www.ImageShack.us

More info about XFCE can be found HERE

quinta-feira, novembro 24, 2005

Ubuntu 5.10 Breezy Badger, Best Desktop for Small Business

No, this conclusion is not mine, my conclusion would be something like, "Ubuntu, best linux eva!".

Read The full History HERE

How to make BloGTK 1.0 work with Blogger

I decided to try BloGTK to make it easier to add posts in this blog, and for my surprise it didnt work, but it was because i didnt know what to fill up in the account config, but the app itself didnt have any hints or help, it didnt even have a link to a website so i could to read the documentation, so i had to ask my friend Google for help.

And i found the Official BloGTK Website, and reading the FAQ, i found out How to make it work with Blogger

Besides this little problem, BloGTK works as its supposed to, have spell check, preview and some usefull features.

Enjoy :)

Logitech MX310 with 800dpi in Ubuntu Breezy

I was postponing this, but i m kinda bored today, so i decided to make some tweaks in my ubuntu box, and i decided to start with my MX310, it was working with 400dpi, but now its working with 800dpi thanx to this HOWTO

Please read it carefully, i m lazy so i didnt read it at first and it didnt work, if you have a MX310 or MX510 mouse, you should download the .gz file attached in the end of the thread.

Enjoy ;)

Find out how many days are in month

It took me a while to find out how to do it using php, but thanx to my beloved friend Google and this tip on the zend.com website, i figured out how to do it, here we go:

$lastday = 29;
while (checkdate($month, $lastday, $year)) {
$lastday++;
}
$lastday -= 1;


Simple isnt it?

Firebird GROUP BY syntax

Yesterday i was proud of myself, and was planning to ask for a job at microsoft, i never had made a code so dirty in my life (not that my codes are clean, but that one was to fucking dirty), i m sure that if i ve sent my code to microsoft they would hire me right away.

I needed a report that could count how many of each product were sold for each day of the month, i tried a lot of stuff but none work.

So i used one select for each day and each product, so a report with 4 products took 120 selects, i m sure microsoft would be proud of me.

But the last thing that i want in my useless life is to work at microsoft or under any microsoft code philosofy, so here is my new query and new code, a lot cleaner and a lot faster, but still noob :)


SELECT SUM(I.item_qtde), N.vnd_data, SUM(N.vnd_total) AS total
FROM vendas N, items_venda I
WHERE N.ved_cod='$ved_cod' AND I.pro_cod='$pro_cod' AND N.vnd_cod=I.vnd_cod
GROUP BY N.vnd_data
ORDER BY N.vnd_data ASC


This GROUP BY stuff was kinda a pain, cause there are some rules to make it work, and i m kinda lazy about reading the fucking manuals, so i tried till it worked.

But now i know that you have to have a SUM or a COUNT in the selected fields, and a field wich the data are gonna be grouped, now it is working perfectly.

segunda-feira, novembro 21, 2005

Some triggers using Firebird 1.5

Man, this Firebird stuff gave me a lot of headaches today, but i m brazilian and never give up :) so in the end i won against it, and learned how to make some triggers, i ll explain what it does.

BEGIN
UPDATE PRODUTOS
SET PRO_EST_ATUAL = (PRO_EST_ATUAL + NEW.EST_QTDE)
WHERE (PRO_COD = NEW.PRO_COD);
END


This was the first one, it is activated after a insert in the estoque (stock) table, and it automatically updates the field pro_est_atual (actual stock) in the produtos (products) table, so each time I insert a new row it automatilly sum the value with the current stock, and add the result to the actual stock field.

The second one was kinda hard work, but it worked as i wanted, here it goes:

BEGIN
UPDATE PRODUTOS SET PRO_EST_ATUAL =
COALESCE((
SELECT SUM(EST_QTDE) FROM ESTOQUE
WHERE PRO_COD = OLD.PRO_COD
),0)
WHERE
PRO_COD = OLD.PRO_COD;
END


This one seens more complicated, but its simple.

It is activated after a delete, and it gets the product code that was deleted (OLD.PRO_COD) and sum all the stock entries for the product again, and after this it writes the new stock value in the produtos (products) table.

Dont ask me about this coalesce stuff, i dont quite understand it.. maybe in a near future i can understand what exactly it does, for now i ll just stfu so i dont say anything wrong :)

domingo, novembro 20, 2005

Problem with stock control with sql and firebird...

Now i m sure, i have to study more about Databases, sql and normalization...

i was with the following problem with a firebird database and a stock control table:

i have to sometimes remove a row, and i have to
rewrite all the actual_stock of the product.. like, if i remove the
second entry.. i have to do it:

id, pro_id, action, quantity, actual_stock
1, 01, A, 10, 0
2, 01, R, 1, 9<-Remove
3, 01, R, 1, 9<-Update
4, 01, R, 1, 8<-Update
5, 01, R, 2, 6<-Update
6, 01, A, 5, 11<-Update


So the solutions posted on the firebird support mail list was the following:

Bill Meaney

You definitely do NOT want to do what you are trying to do in this manner.

If you want the actual_stock so that you can know what you have on hand at
any time you could do this in several different ways.

Drop the actual_stock column from this table. As you have found out this
will cause you headaches. You could use Quantity as a signed value such
that a removed value of 2 was -2. You could then 'A'dd and 'R'emove rows
without any updating. In fact you don't even need the Action column as this
information is known by the sign. You get the stock on hand with the
following query.

SELECT Pro_Id, sum(Quantity) On_Hand
FROM StockControl
WHERE Pro_Id = :Pro_Id



If you need a multiple row set with a running total of On_Hand then you
could write a stored procedure. There is an example in Helen's book.



Adam

This design needs to be normalized, or you will get real problems with
performance

Something like this:

StockControl
(id, pro_id, stock_added)

Stock
(pro_id, actual_stock);

*** Stock_added is negative when you remove and positive otherwise

Now create some triggers on StockControl to manage stock

CREATE TRIGGER SCI ACTIVE AFTER INSERT AS
BEGIN
UPDATE STOCK
SET ACTUAL_STOCK = ACTUAL_STOCK + NEW.STOCK_ADDED
WHERE PRO_ID = NEW.PRO_ID;
END
^


Ok, now every time you add something to stock control, the stock count
is updated in the stock table.

If you want that information, a simple join will do it.

SELECT SC.id, SC.pro_id, SC.stock_added, S.ACTUALSTOCK
FROM STOCKCOUNT SC
JOIN STOCK S ON (SC.PRO_ID = S.PRO_ID)


Judging by the design, you would do well to spend a few hours reading
about normalization.

Hope that helps.


Yes, it helps a lot, and now i m gonna study more about normalization, thanks guys.

select * IS EVIL!

select * IS EVIL!

While taking a quick look at the ##php channel on irc.freenode.org, i got this link:

select * is evil

It explain why you should not use select * in sql queries.
But the better thing in this page is the footer about the author's life, enjoy.

pizza_milkshake is a dedicated computer nerd, fuzzy mathematician and freelance pornstar who's main mission in life is to make as many mistakes as possible and then write about them in the vain hope of doing some good

sexta-feira, novembro 18, 2005