Posts by Woss • 73,416 points
1,476 posts
-
1
votes1
answer89
viewsA: rowCount does not return zero
It will not be displayed on the screen that there are zeros records in the database because the display statement of this value: print $usuario->rowCount(); It’s inside a loop: while($ver =…
-
5
votes1
answer1173
viewsA: Autocomplete list ul>li*n in Sublime Text 3
This type of shortcut is defined in the package Emmet. To use, simply enter the desired structure and press Tab. It is important to note that the shortcut will only work by default on HTML files, so…
-
20
votes4
answers5555
viewsA: Determine the nth Fibonacci term with recursion
Let’s consider the snippet of code you put in the question, just assigning the return of the call to a variable, to simplify the explanation: def fibonacci(n): if n <= 1: return n else: return…
-
0
votes2
answers174
viewsA: CSS - Tbody and TR with different measurements
I believe what you need is to work with the property position elements. For example, considering that the table will be within a div 500px x 500px: .container { width: 500px; height: 200px;…
-
7
votes2
answers166
viewsA: Error trying to recover $_GET value in Submit
This is probably because you have disabled the field DestinoID defining the property disabled. By default, browsers do not send data in disabled fields. If you want this value not to be changed by…
-
3
votes1
answer53
viewsA: Organize information
You can use regular expressions to extract the data: <?php // Dados de entrada: $linha = 'NICK:KEOME PTS:50 ASTS:6 DEFREB:2 OFFREB:7 STLS:14 BLKS:4 TOS:5 NICK:ARTHUR PTS:10 ASTS:3 DEFREB:5…
-
1
votes2
answers83
viewsA: Replace HTML tags
To display the HTML elements, just use the function htmlentities: echo htmlentities("<script>alert('SOpt')</script>"); The exit will be:…
-
40
votes1
answer544
viewsA: What happens in 1...1 in PHP?
In fact, what occurs is the concatenation of values of the type float. PHP analyzes 1. as being float(1.0) and .1 as being float(0.1), in this way, the concatenation of float(1.0) . float(0.1),…
-
29
votes1
answer544
viewsQ: What happens in 1...1 in PHP?
On the web I came across the following piece of code: echo 1...1; Resulting in 10.1. I did the var_dump of the same and the return is: string(4) "10.1" Works with variable assignment: $x = 1...1;…
-
4
votes2
answers98
viewsA: Why doesn’t $.post() return an object?
By default, the function $.post has a fourth parameter that defines the return type. By default, jQuery will try to find out which type is susceptible to failure: $.post(url [, data ] [, success ]…
-
24
votes1
answer3432
viewsA: What is the purpose of Middleware in relation to Apis and Web Applications made in Slim?
William’s words sum up the concept of middleware. The middleware is a structure to work directly on the HTTP protocol, having as input the HTTP request received by the server and as output the…
-
2
votes1
answer193
viewsA: Search for smallest integer available in Mysql
If we consider the following table: CREATE TABLE `products` ( `id` int(3) NOT NULL AUTO_INCREMENT, `name` varchar(20) NOT NULL, `code` int(3) DEFAULT NULL, PRIMARY KEY (`id`) ) With the following…
-
2
votes1
answer77
viewsA: Getting information from an "Object"
Just use the method map of array and return only the attribute name: let names = genres.map(genre => genre.name); Take the example: const genres = [ {id: 28, name: "Ação"}, {id: 12, name:…
javascriptanswered Woss 73,416 -
13
votes2
answers4736
viewsA: How to print text in the same line in Python
A solution is to use the parameter end of function print equal to \r. This causes the pointer to return to the beginning of the same line; however, this does not cause the line to be deleted. Lines…
-
6
votes3
answers2030
viewsA: How to create an empty object in PHP?
In PHP 7 you can still use anonymous classes, including setting methods for such an object: $obj = new class { public function __construct () { $this->key1 = new stdClass();…
-
3
votes3
answers105
viewsA: Add a character dynamically with PHP or Javascript
As commented, the best would be to even adapt your system to accept the value of the original user RG, with 8 characters. But in fact it is possible to add a character X at the end indicating that…
-
4
votes3
answers2681
viewsA: Adding text files to python
When you open a file, a generator referring to the file is returned. You can pass it directly to the method writelines to write your content in the final file. See the example: # Abre o arquivo…
python-3.xanswered Woss 73,416 -
2
votes1
answer658
viewsA: Pass parameter in FILTER of a Javascript array
What you can do is use the concept of decorator, which simplistically is a function that returns another function, applying some treatment on this. In this case, the decorator would receive the…
-
1
votes1
answer87
viewsA: Add onclick() values
As you yourself discovered, the problem is that by doing: var t = $("#gasto").html(); var p = $("#"+a).attr("data-preco"); Both variables will be of type string, for example, "1" and "5",…
-
2
votes2
answers524
viewsA: PHP routines, using Return
For a simple example, as given in the question, it doesn’t really make such a difference between using the return or the echo directly in the result. However, with the complexity of your application…
-
0
votes2
answers103
viewsA: PHP-code conflict - blank page
The error of undefined variable occurs in item 18. The code is commented and is self-explanatory. <?php // (0) Não falta um session_start() aqui? require('config.php'); // (1) Verifica-se se…
-
0
votes1
answer490
viewsA: Error "Trying to get Property of non-object" when using mysqli_stmt_fetch
The function mysqli_stmt_fetch, or the method fetch of the object stmt, has the following form: bool mysqli_stmt::fetch ( void ) // Método fetch do objeto stmt bool mysqli_stmt_fetch ( mysqli_stmt…
-
13
votes1
answer3178
viewsA: What is the difference between package and module in Python?
Module In the documentation says: A module is a file containing Python Definitions and statements. The file name is the module name with the suffix . py appended. I mean, a file foo.py is considered…
-
4
votes1
answer309
viewsA: What is the function of the -m Python option?
You can always run python --help for detailed description of the command and parameters. See output: usage: python [option] ... [-c cmd | -m mod | file | -] [arg] ... Options and arguments (and…
-
4
votes1
answer67
viewsA: How to set an equal value for an object property on all objects in a list?
Considering the entry: let data = [ {"nome": "Carlos","ativo": false}, {"nome": "Joao","ativo": false} ]; In the ES6 standard, you can use Object.assign to merge two objects. See: // Dados de…
javascriptanswered Woss 73,416 -
0
votes2
answers829
viewsA: Import a file containing script and link tags
Like the @jbueno commented, if you use any language on the server side, this treatment will be made much easier on it, be it PHP, Python, C#, Java or any other. Not only easier as recommended.…
-
1
votes4
answers8205
viewsA: How to get the highest value of a python array / vector?
You can still check in real time, at each value read. This will prevent you from creating repeat loops for matrix definition and other repeat loops to fetch the highest value. Take the example: m =…
-
2
votes2
answers29
viewsA: Modify TAG that does not have such a class
CSS works from the most generic to the most specific. That is, you can style all the div with only div { ... } and then stylize .umaclass overwriting the desired properties. Take an example: .teste…
-
2
votes2
answers363
viewsA: how to find if it contains text inside a javascript array
To search for the question and display the answer, just use indexOf in the list of questions to get the position of the question in the list and display the answer used respostas[index]. Take the…
javascriptanswered Woss 73,416 -
3
votes5
answers1088
viewsA: Digits in a java string
You can use regular expression to count the number of digits and to extract them from the text if necessary: import java.util.*; import java.util.regex.*; class Main { public static void…
-
2
votes1
answer129
viewsA: Get unchecked value with PHP
The way you structured your HTML will not allow you to retrieve the data correctly. Note that, considering three products, you will have something like: <div> <input type="text"…
-
2
votes1
answer1130
viewsA: Pick an item from a list
I will describe the programme in parts, as I believe some details can be improved. First, let’s create a list of words that will be part of the guessing game. For each word, there will be five tips.…
-
5
votes2
answers23455
viewsA: Get Data in the JSON structure with python
As it stands, the structure of your data is apparently inconsistent. As commented by Sidon, if used JSON, a format that would make much more sense would be: { "informacao1": "valor_informação1",…
-
1
votes1
answer78
views -
2
votes1
answer671
viewsA: "Undefined index" message when accessing $_POST index
The first time you access the page, you are making an HTTP request using the GET method, so no information will be defined in the global variable $_POST. This way, when you try to get the value of…
-
0
votes1
answer113
views -
0
votes3
answers209
viewsA: Prevent login on a Submit form
You can solve your problem using only HTML 5. For the condition of the email field, simply add the attribute required. When the attribute is defined type as email, browsers with support for this…
-
8
votes6
answers6752
viewsA: Get the list of prime numbers smaller than N
One of the ways to solve this exercise is through Sieve of Eratosthenes. The idea, superficially, is to get the full list of values between 2 and N and remove those that are not primes. The…
-
4
votes3
answers68693
viewsA: How to create a python array
If the intention is only to create a matrix as follows: [" ", " ", " ", ..., " "] [" ", " ", " ", ..., " "] [" ", " ", " ", ..., " "] [ ... ... ...] [" ", " ", " ", ..., " "] Just you do: return [["…
-
0
votes4
answers1139
viewsA: Separating columns from a multidimensional array
The best way is to use the tools that language offers you. Remember that programming language allows you to avoid doing repetitive work. If you do, something does not agree. For example, PHP…
-
11
votes8
answers2184
viewsA: How to know all possible combinations of 0 and 1 in Java?
A simple way, using only one while and without recursion: int x = 0; int n = 5; // Enquanto x < 2^n: while (x < Math.pow(2, n)) { System.out.println( // Converte de int para bin, formatando…
-
13
votes1
answer485
viewsA: What are the advantages and disadvantages of using <? instead of <?php?
It’s interesting to use <? instead of <?php? Not currently. And honestly, I believe it never was. The tag <?php exists at least since version 2 of the language (some places cite that since…
-
2
votes2
answers1104
viewsA: pass the id of an input to another page
As commented, the function of the property id is to identify only one element in DOM, in HTML. If you need this value in PHP, you should not use this attribute. First, because it doesn’t make sense.…
-
3
votes2
answers227
viewsA: Return all birthdays of the month chosen by the user
Let us consider that you have the following list of friends: Amigo[] agenda = { new Amigo("João", "20/01/1983"), new Amigo("Marcia", "12/08/1990"), new Amigo("Lucas", "02/12/1989"), new…
-
2
votes1
answer558
viewsA: Search file and display content
To fetch all files called arquivo.txt in any subdirectory from the root of the application, you can use the function glob: $files = glob("./**/*/arquivo.txt"); In this case, $files will be a list of…
-
1
votes1
answer412
viewsA: Element exceeding the size of the div
Just add display: table in the CSS #portfolio figure, thus the dimensions of the element figure will adjust to the dimensions of img and no more of the screen. #portfolio figure{ position: relative;…
-
3
votes1
answer311
viewsA: Recursion - I want to count how many times digits 3 and 4 appear
Problem Your code has some logic problems. Follow the table test for input 23334: The function count is called with x = '23334'; The value of y is defined as 0; Check the position 0 of x. Fake, move…
python-3.xanswered Woss 73,416 -
4
votes1
answer13093
viewsA: Difference between NULL, empty and Python blank
In Python, if you just do if variavel: ... Any value that is analyzed as true will pass the test. It was not very clear, at least to me, what this object would be pd that you perform the method…
-
3
votes1
answer29
viewsA: Incorrect count of $_FILE fields
When you create the field in HTML, a null value will be sent to PHP, precisely because the field exists and sometimes it is necessary to fill it out, leaving it for the developer to validate. If in…
-
2
votes1
answer15619
viewsA: Find an item in the list
You’ve come very close to the final solution. To check if the candidate has been approved, just check if your number is on the list of classified: if numeroCandidato in classificados:…