Posts by Woss • 73,416 points
1,476 posts
-
2
votes3
answers1419
viewsA: Clicking on <li> the <a> link also work
I believe that using Javascript (and especially jQuery) to change the natural behavior of the element li also not the best solution. This is a classic case of delegating a function to an element…
-
2
votes2
answers5626
viewsA: recursiveness to find odd numbers in a python list
Making the Table test: def encontra_impares(lista): lis = [] if len(lista) == 1 and lista[0] % 2 == 0: if not lista[0] % 2 == 0: return lis return lista else: if lista[0] % 2 == 0: return lista[0] +…
-
3
votes1
answer3070
viewsA: Create Json for PHP based on Mysql
I don’t have PHP lower than 7 on my machine, so I can’t test your code to tell you punctually what the error is, but using Mysqli you can do something like: // Conecta com o banco de dados: $mysqli…
-
4
votes3
answers4922
viewsA: python recursive function to compute sum of the elements of a list
A recursion, in this case, would play the role of the repeat loop, so you don’t need to use both. Your recursive stop condition is correct: if the list has only one element, return it. No else,…
-
1
votes2
answers4815
viewsA: Show and hide SELECT-based field
As commented by colleague Julio Neto, you can enter the function directly in the event onchange of the element select. See the example below: function cadastrarInstituicao() { var instituicao =…
-
1
votes1
answer34
viewsA: Stop running a particular php snippet
Where do you do: if($value->nome_categoria === 'USERS') { $this->return .= 'USERS'; $this->achouUsers = true; while (!$this->achouUsers){ continue; } } if($value->nome_categoria ===…
-
1
votes3
answers124
viewsA: Callback running when loading the page
The functions callbacks that handle events in Javascript are set to the object describing the event as a parameter. The event object has the attribute target representing the target element of this…
javascriptanswered Woss 73,416 -
31
votes5
answers43935
viewsA: What is a Table Test? How to apply it?
What is the Table Test? Table Testing is a manual process that is used to validate the logic of a given algorithm. It is mainly used in algorithms when the language used has no automated debugging…
-
4
votes1
answer1373
viewsA: Text area with image
What you want to do is resolved with WYSIWYG editors (What You See Is What You Get). A simple example of these editors is the Tinymce. To use it: Go to the URL: https://store.ephox.com/signup/ to…
-
42
votes5
answers43935
viewsQ: What is a Table Test? How to apply it?
It is quite common to read while studying algorithms and programming logic that the Table Test is a means of verifying the functioning of an algorithm. What is the Table Test? How is it possible to…
-
3
votes3
answers810
viewsA: Avoid multiple PHP Notice: Undefined index: inside a loop for
The error occurs because PHP tries to access a key from array which may not exist initially. For example, in the first word, $ocorrencias is an empty list and when you do $ocorrencias[$palavra] you…
-
7
votes1
answer4680
viewsA: Error 404 Page PHP STANDARD HTACCES
Redirect error Directional error occurs due to an error in the file .htaccess. In accordance with the documentation, the directive ErrorDocument has the following format: ErrorDocument…
-
10
votes2
answers322
viewsA: What is the HTTP verb I use for logout?
The recommendations set out in RFC 2616, section 9, Method Definitions. DELETE The DELETE method requests that the origin server delete the Resource identified by the Request-URI. This method MAY be…
-
3
votes3
answers156
viewsA: How to know the most used word in all records
Another solution running all the logic in PHP is to use the native functions array_merge and array_map to create the word list, the function array_count_values to calculate the frequency of each…
-
18
votes4
answers4728
viewsA: How to write values to the Mysql database using PHP?
Short answer: no. You need to read it all anyway. TL;DR To fully understand the process, it will be necessary to understand several basic concepts that many novice users fail to study. Many of the…
-
3
votes2
answers290
viewsA: How to leave a number always negative in php?
It seems to me to be a very inelegant solution and does not work precisely for the reason that the error says: PHP will try to interpret the value -1*abs as the function name. Not only will the…
-
2
votes1
answer270
viewsA: Loop for in in getElementsByClassName
The return of getElementsByClassName is an object of the type HTMLCollection, not just an object NodeList. This object has a read-only attribute called length and so-called methods item and…
javascriptanswered Woss 73,416 -
2
votes2
answers389
viewsA: Access the main class instance from an anonymous one in PHP 7
In accordance with the official documentation: Nesting an anonymous class within another class does not give access to any private or protected method, or external class properties. To use the…
-
1
votes1
answer369
views -
2
votes2
answers50
viewsA: How to make a script that generates a random background color on the site?
The function getElementsByTagName returns a list of all elements body document, then you need to define which element you want to handle. In this case, the element is body, there will only be one,…
-
1
votes2
answers946
viewsA: Make border-bottom stand on the same width as text
Just apply the edge to an element span within the element h3. Take an example: h3 { background: #FFFFE0; } h3 > span { border-bottom: 3px solid red; } <h3><span>Stack Overflow em…
-
0
votes1
answer114
viewsA: Undefined variable when trying to add a value in the session
The problem is that you are trying to access an undefined variable. <?php foreach($lista_tarefas as $tarefa){ ?> <tr> <td><?=$tarefa['nome'];?></td>…
-
1
votes1
answer309
viewsA: Is there a tag in Django to show part of the text?
Since the intention is only to limit the number of characters, just use the filter slice: {{ post.description | slice:"0:255" }} This way, characters in positions between 0 and 255 will be…
-
0
votes4
answers1576
viewsA: Pass value to another page
Another solution is to use the element button: <button type="submit" name="plano" value="">Label</button> When defined as type submit and possess the attribute value defined, a key/value…
-
3
votes2
answers243
viewsA: How to make one element continue with effect when passing the mouse on another?
The only problem in your CSS is that you make the effect on the :hover of the button and when the mouse is over the sub-menu, the button loses the property hover. The simplest solution is to pass…
-
2
votes2
answers421
viewsA: Convert and save time to database with PHP
With Laravel it is possible to get the list of all values passed in the request, except for some, through the method: $request->except([...]); So, first we start by storing this list in a…
-
1
votes2
answers369
viewsA: Alignment of div within html
There is a difference between using visibility: hidden and display: none in an element. The difference has been discussed previously here: What is the difference between display:None and…
-
20
votes2
answers907
viewsQ: What is HTTP Response splitting?
Reading about HTTP headers I ended up coming across a function filter that removed both invalid characters from the header field value (header field), how many multiple characters CRLF. This second…
-
28
votes2
answers17718
viewsA: What to use in Ajax, Success or done?
Conceptually they are not the same thing, but the result produced is exactly the same. The functions success and error are called callbacks. In turn, the functions done and fail are methods of a…
-
3
votes4
answers1471
viewsA: Generate random numbers and add them up
To generate n random numbers, use generators: numbers = (random.randint(1, 100) for _ in range(n)) Note: If the number list is used for more than just calculating the sum, do not use generator, but…
-
9
votes3
answers220
viewsA: What is the { } in the code below? and what is the definition for?
Official documentation It basically serves to define the beginning and end of the method name that must be invoked. How the name varies according to the value of $tipo, do only:…
-
1
votes2
answers249
viewsA: Comparison of strpos() variables - PHP
The function strpos searches a text in another and returns the position of the beginning if it is found or false otherwise. The problem of doing: if (strpos($x, $y)) { ... } Is that if the value of…
-
3
votes2
answers1092
viewsA: HTML5 - End date less than start date
Just use the attribute min: <input type="date" id="data_final" min="<?= date("Y-m-d") ?>"> See the example below: <input type="date" id="data_final" min="2017-07-01"> As commented,…
-
4
votes2
answers55
viewsA: What’s the difference from . to -> in PHP?
It was a typo. Run the video more and you will see that when it runs the program, the error appears. https://youtu.be/lOOYBUQSRWU?t=15m26s To access a method in PHP is only through the operator…
-
7
votes2
answers1794
viewsA: How to Thread a class method
I’m not sure I quite understand your problem, but if I do, I believe you won’t need to create a thread just for that. What you can do is deliver the HTTP response of the request to the client and…
-
1
votes1
answer52
viewsA: if on the screen before the query is performed
To execute a PHP code only when the form is submitted, you need to check the HTTP method of the request handled and the fields present in that request. <?php if ($_SERVER["REQUEST_METHOD"] ==…
-
1
votes1
answer227
viewsA: Get information from Twitter without using the Curl API
The Twitter page apparently has a field input[type=hidden] with the data JSON, which makes our life much easier. The result obtained in: $user_info = curl_exec($user); It is nothing more than the…
-
2
votes1
answer49
viewsA: Passing values between functions in PHP
What happens is that the aid function url() of Laravel returns an object of type Illuminate/Routing/UrlGenerator. This class, by itself, has the method to, that returns a string. Do…
-
1
votes1
answer23
viewsA: Problem with $_SESSION with $_GET displaying in unexpected result table
As will be several records composed by name, phone and email, what you need to do is: $_SESSION["lista"][] = array( "nome" => $_GET["nome"], "telefone" => $_GET["telefone"], "email" =>…
-
1
votes3
answers139
viewsA: Get the last "word" of a PATH with different URL formats
PHP already has a native function to work with URL, but as not all are in the format defined in RFC-3986, the function ends up analyzing incorrectly those that are not standardized. Nothing…
-
2
votes2
answers56
viewsA: How to get the contents of dynamic Ivs?
The way you did it is correct, only incomplete. With the selector #lista_medicamentos .item-inner you just capture the div.item-inner, then to capture the name of the medicine, just search for the…
-
1
votes1
answer361
viewsA: Close function when clicking outside the element
Just turning the comment into a response. The problem with your code is assigning the event twice window.onclick, so the second assignment overwrites the first. It’s similar when you do x = 1 and…
javascriptanswered Woss 73,416 -
3
votes3
answers1169
viewsA: How to store the data in a variable and then use a query?
In your HTML, change the value of the attribute value to the id: <label for="cbMedicos">Selecione um Médico</label> <select id="cbMedicos" name="cbMedicos">…
-
5
votes3
answers321
viewsA: How to make a stylized edge?
If the only stylized edge so is left, you can work with the pseudo-elements :before and :after, styling both its edges and its body. See an example where I created the thinnest edge with the element…
-
2
votes1
answer63
viewsA: Error trying to save txt
My initial idea was to respond with more structured and better-to-understand code, but you didn’t make it easy. Lots of information omitted and always getting more confused, so the changes you need…
-
1
votes4
answers3472
viewsA: Replace special characters and uppercase letters
From what I understand, you want to create a kind of Slug in the second input from the data entered in the first. For this, use the function below: function slugify(str) { // Converte o texto para…
-
7
votes3
answers247
viewsA: Concatenation or data sequencing: which performs best?
To make it clear: as stated by Maniero and by William, has many other factors that influence performance more than this detail. If you have performance issues in your project, that’s not what will…
-
10
votes2
answers14794
viewsA: Identify repeated elements in Python list
Using collections.defaultdict is much simpler this calculation: from collections import defaultdict # Define a lista de volares: lista = [3, 2, 4, 7, 3, 8, 2, 3, 8, 1] # Define o objeto que…
-
2
votes2
answers44
viewsA: Adjust string in HTML calculator
Just reverse the order of the function calls a little. I highlighted the code below, but basically you keep the call from .val() with a = *, for so the eval will work. Put the .append(), which…
-
2
votes1
answer337
viewsA: Random order with Mysql paging
What you can do is: SELECT * FROM ( SELECT * FROM tabela1 LIMIT $inicial, $final ) as t ORDER BY RAND(); Thus, the records referring to the pagination are selected by SELECT internal and later are…