Posts by Bacco • 93,720 points
1,184 posts
-
9
votes3
answers4703
viewsA: How do a select pick up 8 lines in a row or more where there are common values?
Here is the complete solution: To query the following was the fruit of a number of considerations, and meets the following requirements: Returns results sorted by field codigo does not group…
-
5
votes3
answers243
viewsA: Regex for hexadecimal colors
To answer the question, here is the version with regex: #?(([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})|([0-9a-f])([0-9a-f])([0-9a-f])) This Regex separates by 3 groups of two hexa characters, or 3…
-
6
votes2
answers1434
viewsA: Show users online
Just use the mysql time functions itself. You don’t even need to calculate the time in PHP: $result = mysql_query("UPDATE novo_usuario SET validade=ADDTIME(NOW(),'0:05:00') WHERE ID=$id_user");…
-
3
votes1
answer80
viewsA: Background and icon on tableView
When the view requests a Decorationrole, simply return a Qpixmap, which can work either a background image or an icon, or even return a Qicon: if(role==Qt::BackgroundColorRole) { const QVariant…
-
6
votes5
answers363
viewsA: What does ? and : within an expression?
The ternary Operator a ? b : c "If a is true, returns b, else it returns c" Let’s look at the example given: var maior = (parseFloat(campo1) > parseFloat(campo2)? campo1 : campo2); The < and…
-
5
votes5
answers29249
viewsA: How to calculate age based on DATE of birth in Mysql based on month and day?
This function gets the exact number of full years based on the birthday date: SELECT YEAR(dHoje)-YEAR(dNasc)-IIF(MONTH(dHoje)*32+DAY(dHoje)<MONTH(dNasc)*32+DAY(dNasc),1,0) Note that it is not…
-
4
votes2
answers407
viewsA: Read Blocker in C
This statement is not always true: "As everyone knows the read of a socket is blocking, IE, always waiting for information in the socket." A socket may or may not be "blocking", it merely depends on…
-
21
votes5
answers17254
viewsA: Generate multiple random numbers without repetition
First, generate an ordered list, in this example from 1 to 1000: var maximo = 1000; var i, arr = []; for (i = 0; i < maximo; i++) { arr[i] = i + 1; } then shuffle the numbers within this array:…
-
11
votes2
answers12416
viewsA: Resize image with PHP while maintaining aspect ratio
Solution with the GD library A very common thing in standard PHP installations is the library GD integrated into the distribution. If this is the case, just use the function imagecopyresampled() to…
-
4
votes1
answer1144
viewsA: Resize components when enlarging window
Solution: layouts You can use layouts instead of placing components directly in the widget at pre-determined positions by fixed coordinates. Its interface becomes much more consistent, becoming…
-
4
votes1
answer114
viewsA: Specific Rewriterule case for a URL
Just put the specific rule for this page before the general rule, and use the [L] flag in the specific rule to indicate that after it, the following should be ignored. See more about rewriterule and…
-
3
votes6
answers14122
viewsA: How to simulate a higher resolution screen to check the behavior of a website?
This has some solutions depending on the machine you are using. For example, video drivers from Video Media allow you to add custom resolutions bigger than your monitor, generating a horizontal and…
-
3
votes3
answers5305
viewsA: Convert string to utf-8
Apparently the conversion worked or was done twice. What can happen is that the page is being shown in another encoding. Try putting <meta charset="UTF-8" /> in the <head>page and see if…
-
9
votes4
answers41617
viewsA: Sign of different Query
First, you have to understand that Null, zero and 0000-00-00 are different things. Also, you have to consider whether you are using datetime or date. For example, you could test the query just like…
-
4
votes2
answers1120
viewsA: INNER JOIN does not return database result
Your Join syntax is apparently correct. What remains you check, is whether when entering the details of the worker, if the value of the tb_trabalhador.id desired is being included in the…
-
7
votes1
answer689
viewsA: Free access to page 404.html with . htaccess
You can try this way: Options -Indexes RewriteEngine On RewriteCond %{SCRIPT_FILENAME} !-f RewriteCond %{SCRIPT_FILENAME} !-d RewriteRule ^([^/]*)$ index.php?page=$1 [L] RewriteCond…
-
445
votes4
answers233186
viewsA: What is the difference between INNER JOIN and OUTER JOIN?
A brief explanation about Inner, Left, Right, Outer/Full and Cross Join Let’s base these two tables: Using both in all examples, let’s illustrate the most common types of Join. Inner Join This is a…
-
21
votes4
answers4295
viewsA: Way to make a comparison between three variables
The simplest, most direct and objective solution is return ($a === $b && $a === $c); if you just want to compare values, and not types, you can use so: return ($a == $b && $a == $c);…
-
9
votes2
answers633
viewsA: Mysql Query in PHP only works locally
For security, many standard installations and web hosts set the default Mysql user to be usuario@localhost, that is, only local access. If you have administrative access to the server, you need to…
-
41
votes8
answers75484
viewsA: Error - "Cannot Modify header information - headers already sent"
The message Cannot modify header information - headers already sent by indicates that headers have already been sent by PHP. This is caused either by some previous code, or by some literal character…
-
13
votes4
answers7395
viewsA: What’s different from jQuery’s find and filter?
Difference find finds the elements that meet the requested expression that are descendants selector. filter, on the other hand, filter and return all elements matching the selector and also the…
-
9
votes5
answers3608
viewsA: Can the browser "remember" a password programmatically?
I developed a practical solution a while ago, which is in use, consisting of the following: The logged-in user has access to a bookmarklet with a single token It can drag this bookmarklet to the…
-
11
votes2
answers1894
viewsA: How to align strings to use in a listview?
For this you need to use monospaced fonts, such as Courier (or the native Droid Sans Mono, as pointed out by @Alexandre Marcondes). Monospaced fonts, unlike proportional fonts, are those where all…
-
9
votes1
answer296
viewsA: Problem with string alignment
For this you need to use monospaced fonts, such as Courier. Monospaced fonts, unlike proportional fonts, are those where all letters have the same widths. See just the comparison: Example 1 XMILSW…
-
7
votes1
answer774
viewsA: Rewrite URL for "root" accesses but do not block access to sub-domains
Rewritecond You must use the directive RewriteCond to add conditions to apply or not redirect. For example: # Redirect when we have a single parameter RewriteCond %{SCRIPT_FILENAME} !-f RewriteCond…
-
405
votes9
answers31327
viewsA: How to hash passwords safely?
Theory Hash password is always a secondary defense. A server that authenticates needs some information in order to validate a password. A simple system stores the passwords themselves literally, and…
-
13
votes3
answers269
viewsA: How to prevent a method from printing data when calling a third-party API?
You can use the Output Buffer PHP to capture output without sending to client: ob_start(); $this->soapClient = new SoapClient($wsdlLink); $retorno =…
-
18
votes3
answers1636
viewsA: How to create a conditional index in Mysql?
Mysql currently does not support conditional indexes. The best technical repair1 that I see for this specific case is to create an auxiliary table with the following characteristics: CREATE TABLE…
-
5
votes3
answers1058
viewsA: Createelement() method in PHP
Directly there is no function for this, the closest thing is the DOMDocument::createElement, but is oriented to XML. However, it is relatively simple to implement a proper function for this. Here’s…
-
13
votes6
answers23686
viewsA: Difference between absolute and relative Urls in page contents
For the end user, the difference is practically null, because the browser (or application in general) that makes the request will normalize the address in an imperceptible time. However, if you…
-
12
votes6
answers7903
viewsA: When should we allow a column of a table from a database to accept NULL?
Not as a full answer, but as a contribution to the subject: A possible use of Null is to differentiate values where zero numeric and empty string have different meanings of fields with missing…
-
51
votes1
answer830
viewsA: What is the difference between "element element" and "element>element" selectors?
element element { ... The space between two CSS elements is the descending selector. Descendant is any element that is declared inside another. element > element { ... The > between two…
-
24
votes3
answers2673
viewsA: How to make "case-insensitive" comparisons in Sqlite?
Sqlite has case insensitive only to ASCII natively, because one of the goals of the database is precisely to be Lite :) and there is the understanding that any application that relies on specific…
-
18
votes8
answers48170
viewsA: How to calculate a person’s age in SQL Server?
I prefer to go to the more extensive and safe side and use a function with traditional logic of age calculation, to have no problems with rounding and formulas: SELECT…