Posts by bfavaretto • 64,705 points
902 posts
-
1
votes2
answers57
viewsA: I want every time I click on the 'Armchair' function it changes color
A simple way is to check the current color and change based on it. The code is close to your current: function Selecionar(){ var selecionado = document.getElementById("poltronas"); // Se estiver…
-
6
votes2
answers2550
viewsA: Problem implementing icone from font awesome by css
Add this to your CSS: font-weight: 900; From what I see, this character is only available in this font Bold. I don’t understand the reason, will see is because it is f0da :D…
-
1
votes3
answers314
viewsA: unite 2 vectors (a[10], b[10]) into a vector c[20]
Instead of using a third loop to assemble the vector union, it is possible to obtain the same result with memcpy: #include <stdio.h> int main(){ int a[10]; int b[10]; int c[20]; int i;…
canswered bfavaretto 64,705 -
4
votes1
answer85
viewsA: How to catch the Elements of a json?
For what you’ve shown, response.paymentMethods.CREDIT_CARD.options brings the whole object. I want to count how many options you have and take them dynamically. I don’t know if I got it right, but…
-
1
votes3
answers1191
viewsA: How to add one element inside another
Two things you did wrong: Trying to use a method prependChild that doesn’t exist Try passing a string to this method. Shortest solution var t = document.querySelector("#t"); t.innerHTML = '<div…
javascriptanswered bfavaretto 64,705 -
3
votes3
answers471
viewsA: Delete last comma from a string
// Remove os dois últimos caracteres $str = substr($str, 0, strlen($str)-2); // Acrescenta de volta o ] $str .= ']';
phpanswered bfavaretto 64,705 -
4
votes3
answers86
viewsA: Javascript comparison
Other responses suggest a value check falsey, which excludes more than its condition. Without changing the meaning of your original code, you can simply remove the first or second condition. They…
-
2
votes1
answer199
viewsA: How to transform more than one vector into an array using the php language?
I don’t understand why you treat the different first line. Here’s an example that generates a 4x4 matrix, you can adapt to your case: $str = "0010\n1011\n0000\n0101"; $matriz = []; $linhas =…
-
3
votes4
answers158
viewsA: Javascript pass by value
Other solution besides the Object.assign is to convert the object to JSON and disconnect it into the variable that will receive the copy. The advantage over the assign is that a deep copy will be…
javascriptanswered bfavaretto 64,705 -
2
votes3
answers1812
viewsA: Pick up part of a URL with PHP Explode
If you want to take the parameters passed by GET from any URL - not necessarily the current page, which PHP already makes available in $_GET - there are specific functions for this: parse_url…
phpanswered bfavaretto 64,705 -
5
votes3
answers1524
viewsA: If with 3 conditions and at least 2 true?
Gambiarra based on type Juggling: if(a + b + c >= 2) { } Explanation: with the addition operator, the boolean values will be converted into numbers, with true availing 1 and false availing 0. If…
-
4
votes1
answer84
viewsA: Using LIKE together with BETWEEN
If I understand the question correctly, it must give the result you seek: WHERE LEFT(public.retornotoner.observacao, 1) BETWEEN 'A' AND 'S' See working on Sqlfiddle…
postgresqlanswered bfavaretto 64,705 -
2
votes1
answer155
viewsA: Import external URL array with PHP
This content is in JSON, missed you decode. Do so: $contents = json_decode(curl_get_contents($url)); print_r($contents); This will generate an array of objects. If you need an array of (associative)…
-
1
votes1
answer837
viewsA: return array(array) of a php function
Simply use: return $tabela; In doing return array($tabela) you are wrapping the whole table (which was already an array) in a new array.
-
5
votes2
answers1922
viewsA: Access indices of an array inside another array
I’d mess with your structure a little bit, like this: $array = array( array( 'loja' => 'Loja1', 'produtos' => array( array( 'produto' => 'bolsa', 'qtd' => 1 ), array( 'produto' =>…
-
18
votes2
answers775
viewsA: What are Truthy and falsy values?
Javascript has a type coercion mechanism: when a value of a certain type is used in a context that expects a different type, an implicit conversion to the expected type occurs. This is the case of…
-
12
votes2
answers2928
viewsA: What’s the difference between For, Foreach and Find in Javascript?
The for is one of the most basic ways to create loops in the language, along with the while and the do..while. It allows you to repeat a code snippet a certain number of times, usually based on a…
-
13
votes1
answer84
viewsA: Is it recommended to use loose Return in a PHP file? When?
In certain cases this makes sense. Forget this question of good practice, do not use if you do not know exactly what you are doing. The php manual explains well how the return when used out of…
phpanswered bfavaretto 64,705 -
2
votes1
answer32
viewsA: How to concatenate this js
It’s simple, you use either single quotes or double quotes: window.location.href = "secreto.php?lat=" + secreto + "&long=" + secreto2; There are cases where you need quotes (single or double) in…
jqueryanswered bfavaretto 64,705 -
1
votes1
answer96
viewsA: Javascript does not load function
Because you have declared your function within another, and not in the global scope. Do so: cep.js function exibe() { alert ('Hello'); }
-
1
votes1
answer159
viewsA: Vue component is not pushing in props
I think it’s because you declared the method as Arrow Function. In that case, the this inside will be the thismost external module, not its component. Try one of these options: // ... methods: {…
-
1
votes1
answer581
viewsA: Use require() (or other method) in Nodejs as in PHP
Node.js uses modules you can import. For example: // modulo.js module.exports = { 'funcao' : function() { return 'função executada'; }, 'propriedade' : 10 } // principal.js const meuModulo =…
-
1
votes2
answers846
viewsA: Import Vue or other components into child components
You can pass your store of Vuex in the creation of the app in the same way that passes the router. Something like this: import Vue from 'vue'; import Vuex from 'vuex'; Vue.use(Vuex); const store =…
-
3
votes2
answers118
viewsA: Problem leaving a background img no body{} reponsive
Change background: url(../img/fundo.jpg); for background-image: url(../img/fundo.jpg);. When you wear it alone background is using a shortcut to multiple properties at the same time. This is…
cssanswered bfavaretto 64,705 -
6
votes3
answers5868
viewsA: Compare values between Array’s Javascript
Just go through one of the arrays, checking in the other if each number of the first one is present in it. The numbers that hit you can store in a third array. There are several ways to do this,…
-
1
votes1
answer113
viewsA: access variable within setInterval
We can not say what would be the best solution in its context, because we do not know more details of the code. But one possibility is to take advantage of the functioning of closures. In summary,…
javascriptanswered bfavaretto 64,705 -
2
votes2
answers554
viewsA: How to create a Function and call your methods without using new, similar to jQuery’s $ ?
In Javascript functions are special types of objects, and can have properties (including other functions) like any object: function funcao(x) { console.log('função chamada'); } funcao.propriedade =…
-
2
votes1
answer78
viewsA: Doubt about the creation of an object
It is possible to access properties and methods by name (such as string) using square brackets instead of the dot. You can do so: function Desenhar(tipoDesenho) { var cards = new lib[tipoDesenho]();…
javascriptanswered bfavaretto 64,705 -
0
votes1
answer142
viewsA: Problem when checking if user already exists before registering
Your search query is wrong, it should be so: SELECT * FROM categorias WHERE nomeCategoria = '$adicionar_categoria' LIMIT 1 HOWEVER: your code has serious compatibility and safety problems. I…
-
0
votes2
answers103
viewsA: Why does the number variable return an empty string when declaring it outside a function
At the time you do it: var numero = document.getElementById("numero").value; You are copying the value of the field for the variable. As when loading the page this field is empty, the variable is…
-
2
votes3
answers2107
viewsA: How to print only a part of HTML?
There are several ways to do this, some with Javascript, others with CSS only. A good way is to start with the simplest, as this solution only with CSS, posted by Bennett Mcelwee in the OS in…
-
2
votes1
answer69
viewsA: Take html from a tag, including the tag itself
With pure Javascript, just grab the outerHTML element. For example, for that span: var span = document.querySelector('#play1_3_2'); var html = span.outerHTML; console.log(html); <span…
-
0
votes1
answer94
viewsA: How to get next Friday’s date
The function strtotime allows generating dates from strings like "next Friday" (in English): echo date('Y-m-d', strtotime('next Friday')); See working.…
phpanswered bfavaretto 64,705 -
3
votes1
answer37
viewsA: Is using Super Global obsolete and insecure?
No, use superglobal is not obsolete or unsafe. What is obsolete and unsafe is linking to directive register_globals, that creates global variables based on superglobal variables. For example,…
phpanswered bfavaretto 64,705 -
2
votes1
answer117
viewsA: Vue js render video
Try it like this: import v1 from "../../assets/videos/v1.mp4"; import v2 from "../../assets/videos/v2.mp4"; export default { data: () => ({ videos: [ { title: "v1", src: v1, desc: "v1"}, { title:…
-
1
votes1
answer339
viewsA: Increment variable with loop for and while together
Increment $i inside the loop, and change the condition to check whether you arrived at the maximum: $qtde = $result->num_rows; $i = 0; while($row = $result->fetch_assoc() && $i <…
phpanswered bfavaretto 64,705 -
1
votes1
answer6506
viewsA: How to put string and variables together in Portugol?
Use commas to interpolate strings and variables: escreval(aluno, ", sua média é ", media)
-
2
votes1
answer45
viewsA: Array js giving error
If each item in the image array is also an array, you need to declare them within your loop: imagem[i] = []; imagem[i].push(tMin + "% { margin-left:-" + tempoImagens + "%};"); imagem[i].push(tMax +…
javascriptanswered bfavaretto 64,705 -
0
votes1
answer42
viewsA: Absolute address (including script) in PHP
It seems you have a syntax error there. Try it like this: $protocolo = empty($_SERVER['HTTPS']) ? 'http://': 'https://'; $url = $protocolo . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; echo…
phpanswered bfavaretto 64,705 -
2
votes2
answers124
viewsA: How to Change Ifs to For
To give you a start, because there’s a lot to improve on my code: var indisponiveis = []; $('.select').on('change', function(e) { var _select = this; var select = $(this); var valor = select.val();…
-
4
votes1
answer78
viewsA: Change scenarios with loop
A way to do it, not very pretty but it works: In variable declarations include: int season = 0; // 0=summer, 1=fall, 2=winter Create this new method: void changeSeason() { // Gira o índice da…
canswered bfavaretto 64,705 -
1
votes3
answers97
viewsA: Execution or not of the increment in loops for
Although the instruction on increment comes at the beginning of the loop for, you can consider that this increment actually runs just after the body of the loop, before the next check on the stop…
-
1
votes1
answer30
viewsA: Query does not return setted WHERE
Their OR are not being interpreted in the way you expect, and are being applied in relation to all AND together. Do so like this: WHERE dtnota BETWEEN "01/01/2015" AND "31/12/2015" AND…
-
0
votes1
answer38
viewsA: Data count in php
If I understood the situation correctly, this query would bring the sums already ordered, for each codBaixa that exists in the period: SELECT codBaixa, COUNT(*) AS total FROM net_virtua WHERE data…
-
0
votes1
answer733
viewsA: Ajax request error with Codeigniter (url)
Your Javascript code is not being processed by PHP. And that’s good, it usually doesn’t pay to have PHP process the JS, they are served more efficiently if they’re static. One possible solution is…
-
6
votes2
answers503
viewsA: Difference Location.href or Location.assign
There is no difference - except that href is a property, and thus also allows the reading of its value, while the method assign only allows the definition of this value (and consequently the loading…
javascriptanswered bfavaretto 64,705 -
1
votes1
answer144
viewsA: How to get the largest sum on a table?
Grouping the results, adding and picking the first item: SELECT produto, SUM(vendas) AS total_vendas FROM produtos GROUP BY produto -- agrupando pelo nome (o ideal seria id) ORDER BY SUM(vendas)…
mysqlanswered bfavaretto 64,705 -
6
votes3
answers5488
viewsA: How to use the current value of a variable in a more internal function?
With modern Javascript (ES-2015+) The other answers remain valid, but nowadays we have a standard solution for this with modern Javascript, using variables with block scope declared with let. You…
-
7
votes3
answers729
viewsA: Get font size in HTML
With the overall function getComputedStyle: var elemento = document.getElementById('elemento'); // ou $('#elemento')[0] var estilos = window.getComputedStyle(elemento, null); var tamanho =…
-
5
votes1
answer66
viewsA: What does that code do?
This code is very confusing, but it does one simple thing: if the value of $campo for "Não Informado", transforms the value of the field into ''. The first thing executed in that code is $campo ==…
phpanswered bfavaretto 64,705