Posts by Bacco • 93,720 points
1,184 posts
-
4
votes1
answer49
viewsA: retrieve date from bash Ubuntu
The same way you used to %d-%m-%Y, just use %H-%M-%S General solution in Bash, if you want to store in variable instead of repeating the 3x command: BKP_NAME=$(date -u +%Y-%m-%d_%H-%M-%S_UTC) Local…
-
1
votes1
answer71
viewsA: Page for each user created in the database
Basically this: // ... lógica do login ... header('Location: /'.$nomedousuario); die(); Sanitize the data to make sure that $nomedousuário no special characters. If you have, you will need to use…
-
4
votes1
answer108
viewsA: Mysql variables do not work with php mysqli_fetch_array()
The problem is that they are darlings separated: SET @totVenda := (SELECT SUM(total) FROM tb_produto_item_estoque_saida); SET @totPorcentagem := (SELECT SUM((ROUND((total/@totVenda*100),2))...…
-
4
votes2
answers57
viewsA: Convert string "11092018" to date format "11-09-2018"?
Has many ways. Using the function substr $formatada = substr($string,0,2).'-'.substr($string,2,2).'-'.substr($string,4,4); See working on IDEONE. Handbook:…
-
3
votes2
answers841
views -
4
votes2
answers82
viewsA: Doubt about attributes and POO methods in PHP
Simply the "print" of the last part you mentioned, is a method of Usuario. Note on this line: public function cadastrar(array $produtos, Usuario $usuario) ^^^^^^^ The "register" method waits for a…
-
2
votes1
answer174
viewsA: Classes and scope of php variables
If you want to refer to the class member, and not to any variable, you need to make explicit: catch (PDOException $e) { $this->msgErro = $e->getmessage(); } // ^ // | // --------- O $this se…
-
1
votes2
answers49
viewsA: My arraylist is returning the same value on all "nodes"
The problem is that you create only one User out of the loop: User u = new User(); And inside you change the data, but always the same User: u.setName(divider[0]); u.setLogin(divider[1]);…
-
2
votes1
answer58
viewsA: Does anyone know where the error in this code is?
The error is in the use of end(). The manual is your friend: mixed end ( array &$array ) http://php.net/manual/en/function.end.php The function specifically expects a array referenced (&)…
-
1
votes1
answer95
viewsA: Select in option
Your problem is you’re getting the <option> two-seat: $sql_nome_for = "SELECT nome FROM cad_for WHERE id = '$cod_fornecedor'"; $sql_nome_for = $pdo->query($sql_nome_for); $dado_for =…
-
10
votes2
answers1079
viewsA: How to do a random query in Mysql without repeating data?
A simple solution would be to make ORDER BY RAND in the entire table before starting paging, storing only the image Ids. It’s an extra job, but only storing the Ids in the first "past". Having the…
-
8
votes1
answer740
viewsA: Add sequence of numbers in Javascript
Yes, just use a formula. resultado = n(n+1)/2 See working: var num = 40391; var res = (num * (num - 1))/2; /* adaptado o "-1" para o enunciado da pergunta */ /* que diz que input 40391 resulta em…
-
7
votes1
answer786
viewsA: What is an exponential backoff?
It is a strategy where each attempt or iteration of a procedure is followed by an increasing interval (optionally up to a fixed limit) in the event of failure or need for flow adjustment. Feedback…
pattern-designanswered Bacco 93,720 -
5
votes1
answer376
viewsA: How to specify a time when changing colors with :Hover?
Just use transition: transition: color .7s; ^ ^--- tempo que vai durar | -- propriedade que quer suave Heed for a detail: in your case (and in most of them) you will apply the transition in the…
-
6
votes1
answer142
viewsA: How does "umask" work in PHP and when should we use it or not?
Before understanding the umask, you must understand the permissions of filesystem systems *Nix, some answers in the posts here can help: What are the risks of using permission 777? Permission denied…
-
3
votes3
answers418
views -
15
votes3
answers418
views -
1
votes2
answers72
views -
5
votes3
answers840
viewsA: How to set a limit of 4 images per line?
This would be very easy to do with a server-side language, but as it was not put this option in the question, let’s go from CSS. In the examples below were used img and div, but logic serves for any…
-
9
votes2
answers169
viewsA: How do I delete empty lists from my list?
This line here has a problem: results = [[int(entry) for entry in line.split() != []] for line in f.readlines()] # ^-- falta um IF When you use the for conditionally, must use the format for name in…
-
5
votes2
answers1498
viewsA: Concatenate SH command results on a line
There are many ways, that’s one: echo `date +"%Y-%m-%d %H:%M"` \; `ps -ef | grep osh | wc -l` \; `ps -ef | wc -l` >> log.csv Everything that comes between backticks is executed by the shell,…
-
6
votes2
answers138
viewsA: CSS - How to create a button or design like this reversed
Can be done with CSS2 and borders, without distorting the text: .trapezio{ display:block; position:relative; float:left; margin:20px; width:200px; /* largura da caixa */ line-height:50px; /* altura…
-
5
votes3
answers4410
viewsA: How to remove whitespace from a string with Regex in PHP?
You have requested Regex, but do not need it, if you have access to the attribute content you can use string more efficient: $com = "' smiley. gif'"; $sem = str_replace(' ', '', $com); If you have…
-
3
votes1
answer208
viewsA: Can anyone tell me why my console doesn’t show up as a result of anything?
I’ve made some corrections and adjustments, and I’ve listed them for you to understand the effects of each change: Changed condition i < n for i <= n so that the number of lines matches the…
-
3
votes2
answers125
viewsA: How to know if a certain value is within a specific table
Can make a function to iterate: function Set (list) local set = {} for _, l in ipairs(list) do set[l] = true end return set end And wear it like this local items = Set { "apple", "orange", "pear",…
-
9
votes1
answer322
viewsA: Concatenate columns into rows
If you want line by line, the way is union SELECT SUM(`dias2produto`+`dias4produto`) AS 'Até 4 dias', SUM(ROUND((((`dias2produto`+`dias4produto`)*100)/`total_produto`),2)) as p4d UNION SELECT…
-
3
votes2
answers55
viewsA: Why do I get different results for the same values sent to a PHP function?
As I had already posted in the comments, it is a rounding problem caused by the use of float. I suggest changing this way: function Func_1($dec){ $seconds = round($dec * 3600); // <----…
-
4
votes4
answers360
viewsA: How do I remove characters from a string to a certain extent? in PHP
PHP already has its own function for this: $final = strstr($numeros,'-',true); See working on IDEONE. Handbook: https://secure.php.net/manual/en/function.stristr.php There are other ways: $final =…
-
4
votes2
answers439
viewsA: Calculate sequence of triangular numbers smaller than 1000
The problem is that the for tests the condition before executing the inner block, then the test b < 1000 occurs before the b = (a + 1) + b;. A simple solution would be to pass the calculation…
-
4
votes2
answers1270
viewsA: Is the dot and comma character (;) allowed in filenames?
In principle, you can, but if you’re going to use it by command line, you need "escape" or Unix quotes. Although accepted in the filename, in Shell it has a special meaning, it separates the…
-
3
votes1
answer49
viewsA: Fixed menu hides even with z-index
It is correct the behavior of the content, according to your CSS it should come over the menu. By default the z-index of the elements is zero, and the render order when the values "draw" is to draw…
-
17
votes1
answer363
viewsA: Are there differences between /, /* */ and #?
The essential thing is this: The // and the # are identical in terms of operation; The // and the /* are completely different in terms of operation, and each has a specific use scenario: The // or #…
-
3
votes1
answer55
viewsA: menu marked according to php page
Basically this (adjust the variables): for ($i=0; $i < 26; $i++) { $letra=Chr(97+$i); if ($urlAtual == $letra) { echo "<html do $letra SELECIONADO>"; } else { echo "<html do $letra…
-
5
votes4
answers5283
views -
6
votes1
answer148
viewsA: Problem with include causing unwanted space
The problem you mentioned is the result of two special characters used in UTF to indicate the order of bytes. Are called Byte Order Mark (GOOD). In hexadecimal, they are the sequence 0xFEFF or…
-
2
votes1
answer100
viewsA: Function loop returns only one value
Here’s a problem: function pegarDados ($valorUrl) { $url = $valorUrl; $html = file_get_contents($url); $doc = new DOMDocument(); @$doc->loadHTML($html); $tags =…
-
4
votes2
answers93
viewsA: How to disable a Qlineedit in Pyqt?
Complementing the response of LINQ: You can also use the method setEnabled ("enabled" = "enabled"): inputUserName.setEnabled(False) #desabilita o controle inputUserName.setEnabled(True) #habilita o…
-
7
votes3
answers190
viewsA: CSS catch siblings before element?
CSS does not have a selector that solves precedence, but in your case a "double Hover" can solve it (works on IE11, including): .main{ width: 100%; height:50px; } .child{ width:50px; height:50px;…
-
1
votes2
answers1049
viewsA: How to query MYSQL and PHP using an array as a WHERE pro condition
Mysql has its own function for this, the FIND_IN_SET. The FIND_IN_SET( string1, string2 ) returns true if the first value (string1) is contained in a comma-separated list passed in string2 Applying…
-
9
votes1
answer41
viewsA: Does anyone know what I have to do on this table so it doesn’t get crooked like that?
The problem is that you are creating several independent tables (look at the source of your page to better understand). Take the table structure out of the loop, so it will have multiple rows in the…
-
2
votes1
answer87
viewsA: Problem with Python script
Basically missing the ":" at the end of the if and of else print("Agora eu vou dizer algo para você.") idade = int(input("Me diga sua idade.")) if idade < 18: print("Me desculpe, você não pode…
-
7
votes2
answers190
viewsA: How to know the difference between language construction and function in PHP?
Checking with function_exists: PHP has a suitable function for this, which returns true for functions, but returns false for constructions like require, etc..: bool function_exists ( string…
-
4
votes2
answers1168
viewsA: Function to calculate the Checker Digit of an EAN-13 code
Follows an alternative: function generateEANdigit($code) { $weightflag = true; $sum = 0; for ($i = strlen($code) - 1; $i >= 0; $i--) { $sum += (int)$code[$i] * ($weightflag?3:1); $weightflag =…
-
5
votes1
answer70
viewsA: Know the smallest number with Function min()
The problem is you’re comparing the list values and not the individual value value. Wrong: if smallest is None or values < smallest: # ^^^ Essa é sua lista, e não o valor iterado Corrected: if…
-
5
votes3
answers443
viewsA: Get Integer value in final . 00 and float value in . 01 to 0.9
There are many ways, here are some: Using Regex static String autocasas(double numero) { return String.valueOf(numero).replaceAll("(\\.?0+|\\.)$",""); } See working on IDEONE. Basically we’re…
-
4
votes2
answers36
viewsA: Return desirable amount
The correct answer is colleague Valdeirpsr’s comment. You are spoiling the array in the loop: for ($i=0; $i < $retornar ; $i++) { $ccs = $ccs[$i]; echo $ccs; // Na segunda iteração, a linha…
-
3
votes1
answer287
viewsA: relate two tables listing only last php record
Dividing the problem into parts With that query we get the biggest provaID of each matricula: SELECT matricula, MAX(provaID) AS prova FROM gabarito GROUP BY matricula The GROUP BY causes only one…
-
4
votes1
answer1151
viewsA: Add up final total value using group by Mysql?
To reuse a query can use a @variavel next to Mysql instead of PHP: I made an example with simple values, for you to understand the isolated use of the variable. then you have to adapt to your…
-
3
votes1
answer179
viewsA: Mark current page number (PHP paging)
Just compare to the current page: if (($i >=1) && ($i <= $num_pagina)){ if ($i == $pagina) { // se é a atual, nem do link precisa (conforme o caso)…
-
2
votes1
answer245
viewsA: Mysql comparing a number with string returns true if the string starts with the number
The problem is that there is an implicit cast of string sought, because you are comparing a number with a string. You can force the interpretation of idUser as string in this way: CAST(`idUser` AS…