this part i need to understand \(\displaystyle (P - x)\) because i see the distance from \(\displaystyle dx\) to \(\displaystyle P\) is \(\displaystyle (x + P)\)
Both are correct. It depends on how you will integrate.
If you will integrate normally, you do this:
[imath]\displaystyle \int_{0}^{-L}k\frac{\lambda}{(P - x)^2} \ dx[/imath]
If you will play fancy, taking the left side positive, you do this:
[imath]\displaystyle \int_{0}^{L}k\frac{\lambda}{(P + x)^2} \ dx[/imath]
Solve them, they should give you the same result. Also solve the one in the website that you have given, you should get the same result as well. Why? Because the coordinate system is just a reference system. It will not affect on the result as long as the point [imath]P[/imath] is in front of the rod. If the rod is positively charged, the electric field at [imath]P[/imath] due to the rod will point to the right (east). If the rod is negatively charged, the electric field at [imath]P[/imath] due to the rod will point to the left (west).
How will you solve the problem if the charge is non-uniformly distributed?
Well they will tell you how the charge [imath]Q[/imath] is distributed by giving you more information about the charge density [imath]\lambda[/imath].
Scenarios:
1. The charge density is directly proportional to [imath]x[/imath]. In other words, [imath]\lambda = ax[/imath].
2. The charge density is inversely proportional to [imath]x[/imath]. In other words, [imath]\displaystyle \lambda = \frac{a}{x}[/imath].
3. [imath]\lambda = ax^2[/imath].
4. [imath]\lambda = a(x - x^2)[/imath].
When the charge density is non-uniform, the difficulty of solving the integral will increase. For example, if we take scenario
#1 with our original problem assuming the charge is not uniformly distributed, the integral will be:
[imath]\displaystyle \int_{0}^{-L}k\frac{\lambda}{(P - x)^2} \ dx = \int_{0}^{-L}k\frac{ax}{(P - x)^2} \ dx[/imath]
And you need to do one more step to find the constant [imath]a[/imath].
[imath]\displaystyle Q = \int_{0}^{L} \lambda \ dx = \int_{0}^{L} ax \ dx[/imath]
[imath]\displaystyle a = \frac{Q}{\int_{0}^{L} x \ dx}[/imath]
Note: If we have a thin rod of length [imath]L[/imath], the relation between the charge [imath]Q[/imath] and the charge density [imath]\displaystyle \lambda[/imath] is: [imath]\lambda = \frac{Q}{L}[/imath].