Posts by Bacco • 93,720 points
1,184 posts
-
2
votes1
answer2576
viewsA: PHP Fatal error: [] Operator not supported for strings in
The error is being correctly indicated. You create a string at the beginning of the code: $data = ... That is, a string. In the loop you want to add items: $data[] = ... Items are added in arrays,…
-
9
votes2
answers333
viewsA: What is the Technological Singularity?
As a general concept (uniqueness) In engineering, uniqueness is when a mechanism reaches a state where you can’t predict what happens next. https://en.wikipedia.org/wiki/Mechanical_singularity In…
-
9
votes1
answer1065
viewsA: How do I store various values in each "option" of a "select"?
Storing arbitrary data in a tag Using data-attributes we can put arbitrary data in almost any HTML tag. In our case, we can put various values in option in this way: <option value="Rua Um"…
-
8
votes1
answer301
viewsA: Is coding a URL important?
The importance is to work right: Comparing to a programming language: it’s the same thing as encoding quotes inside a string. For the interpretation of quotation marks to work, you cannot have a…
-
3
votes1
answer51
viewsA: PHP page does not identify SELECT result
Probably the problem is the use of this function: mysqli_affected_rows The mysqli_affected_rows serves to obtain the number of changes to a DELETE or UPDATE, or to identify whether the operation is…
-
7
votes2
answers1940
viewsA: Add a number in front of all records
If you want a fixed number of houses: SELECT LPAD( campo, 6, '0') AS comzeros; If you want a zero: SELECT CONCAT( '0', campo) AS umzero; If you have the problem of spaces before, you can do a CAST:…
-
4
votes1
answer445
viewsA: How does "Restore" and "save" work?
Basically the .save keeps the current state of the context: The current transformation matrix; the cut-off region; the dashed list; and the values of all these attributes: strokeStyle, fillStyle,…
-
4
votes1
answer6718
viewsA: Use str_replace to replace key variable values
That would be right: $codigo = str_replace('nav-link', 'nav-link active', $codigo); The reason is that the replace is not done in the string original. A new string with the changed value, which is…
-
4
votes2
answers824
viewsA: Return predefined values depending on logical condition
Flow Control with Mysql Mysql has four flow operators (five note that the CASE has two forms, one similar to the if programming languages, and another similar to switch: CASE Forma 1: CASE WHEN…
-
1
votes1
answer43
viewsA: ID for undefined change
If you’re using POST on the form, you won’t be able to use the $_GET to get the ID, unless it is in the URL. One solution is to do this: if (isset($_GET['id'])) { $id = (int) $_GET['id']; } elseif…
-
1
votes2
answers143
viewsA: Htaccess that directs to https and also to www
Basically this: RewriteEngine On RewriteCond %{HTTPS} !on [OR] RewriteCond %{HTTP_HOST} !^www\.endereco\.com$ [NC] RewriteRule ^(.*)$ https://www.endereco.com/$1 [L,R=301] RewriteCond %{HTTPS} !on…
-
5
votes1
answer522
viewsA: How to connect tables that are in different databases?
Joining tables with UNION and JOIN: You use UNION in "Vertical", to relate according to the question, in separate lines: Search in multiple tables What’s the difference between UNION and UNION ALL?…
-
14
votes1
answer896
viewsA: What is MUSL? What are the pros of someone carrying it on my laptop?
To musl (whose name is written in lowercase on the official page) is a Standard library of C. According to its author, it aims to be a libc clean, standard and efficient. Your target OS is the Linux…
-
2
votes1
answer46
viewsA: Decoding Mysql - Javascript
Basically it is a matter of saving your previous encoding in the right encoding, see in the options of your code editor (or DB utility) how to save as UTF-8 (or the encoding you will use on your…
-
4
votes2
answers273
views -
7
votes1
answer218
viewsA: Remove comment lines from TXT files
First of all, you can read the file on array in this way: $linhas = file($arquivo, FILE_IGNORE_NEW_LINES); Handbook: http://php.net/manual/en/function.file.php Then just remove the unwanted lines:…
-
2
votes3
answers1555
viewsA: PHP - Error when trying to log in - mysqli_num_rows() expects Parameter 1 to be mysqli_result
Basic error of typing. This line makes no sense: $query = mysqli_select_db($conn, "SELECT * FROM login WHERE user=... The function to execute a query is this: $query = mysqli_query($conn, "SELECT *…
-
2
votes2
answers1448
viewsA: How do I get a specific column from a . txt file with PHP
In the case of an SDF or fixed width SDF is a file delimited by spaces (and/or fixed columns). In this case, just use the substr. Syntax: string substr ( string $string , int $inicio[, int $tamanho]…
-
2
votes1
answer548
viewsA: Record sequential number per year PHP
In pure SQL you can get the next serial so: SELECT CONCAT( YEAR(CURRENT_DATE) % 100, LPAD( COALESCE( MAX(serial_do_ano), 0 ) + 1, 4, '0' ) ) AS serial FROM tabela WHERE YEAR(CURRENT_DATE) =…
-
3
votes1
answer247
viewsA: Calculation in php giving error
You have two immediate problems in the code: You are not checking whether the POST value is correct, and mixing multiplication with concatenation. Test with this: $valorasercalculado =…
-
5
votes2
answers4096
viewsA: Create and manipulate array with classic Asp
To use keys and values in Classic ASP you have the Dictionary: Set registro = Server.CreateObject("Scripting.Dictionary") registro.Add "codigo", "12233" registro.Add "municipio", "santo olavo" ...…
-
8
votes1
answer7322
viewsA: How to create.php file using php?
Basically: <?php $conteudo = '<?php phpinfo(); ?>'; file_put_contents('novophp.php', $conteudo); Handbook: http://php.net/manual/en/function.file-put-contents.php Or so: $conteudo =…
-
2
votes1
answer104
viewsA: Condition in Mysql - CASE X = Y THEN Where - Is it possible?
The CASE is very versatile, and can be used in many contexts, but in your specific situation it is not necessary or appropriate. With the use of AND and OR already resolves: SELECT * FROM…
-
10
votes1
answer149
viewsA: How do I set the file size in a Download response?
Basically: response.AddHeader("Content-Length", "tamanho" ); Remember that the size is in bytes, and only the body of the request, without the headers. Usually the functions that deal with the…
-
13
votes2
answers2142
viewsA: Logic to validate free schedules on schedule
The problem is organizing logic (which is simple). Basically for one time not to coincide with another, you need only two conditions: If you want to get Non coincident hours - "free" are just these…
-
4
votes3
answers1628
viewsA: Convert seconds into days
A day has 86400 seconds ( 60 * 60 * 24 ). To convert seconds into days: $dias = $segundos / 86400; If you don’t want decimals, round down: $dias = floor( $segundos / 86400 ); rounding up: $dias =…
-
2
votes1
answer18
viewsA: Syntax to put more than one id to pick up certain products from the bank
Yes, it’s a syntax error. One solution is this: $sql = "SELECT * FROM camiseta_Masc WHERE id IN (1,2,3)"; See working on SQL FIDDLE. Errors of this nature can be solved by reading the language…
-
1
votes1
answer173
viewsA: How to hide cookies.txt from the Curl
There are already a number of posts on the site about how to block an external client from accessing a file. For example, if it is an Apache server: /search?q=.htaccess+bloquear Best thing would be…
-
4
votes1
answer470
viewsA: Remove Visual Studio Code Side Panel
If it is the map mode native, present in new versions of Vscode, change this: "editor.minimap.enabled": false Link to the manual: https://code.visualstudio.com/updates/v1_10#_preview-minimap If it…
visual-studio-codeanswered Bacco 93,720 -
8
votes4
answers865
viewsA: Split a 16-digit number in PHP
Based on the @rray response $separado = implode(' ', str_split('9999999999999999', 4)); If I wanted to score: $separado = implode('.', str_split('9999999999999999', 4)); As explained above, the…
-
2
votes2
answers205
viewsA: How to return hexadecimal color randomly
A very simple way is to use rgb() instead of #hex: $red: random(256)-1; $green: random(256)-1; $blue: random(256)-1; And then: color: rgb($red, $green, $blue); Or background-color: rgba($red,…
-
5
votes2
answers1041
viewsA: How to optimize plot calculation on "broken" values
It has more than one strategy, but almost all are based on the accumulation of error and discount at the end. In a very simple version of the implementation, you calculate the value of the…
-
4
votes2
answers95
views -
6
votes1
answer612
viewsA: Pass PHP variable to Python longer than 14 characters
You’re running into a numerical accuracy problem. PHP has the maximum 32-bit integer value 2147483647, in 64 bits the value 9223372036854775807 and above this will have a float, with possible loss…
-
2
votes2
answers771
viewsA: Sort foreach in php
It would be the case to first collect the data, and order while displaying: // Primeiro coletamos os resultados em $results foreach (hash_algos() as $hash_algos) { $hash = hash($hash_algos, "salt",…
-
2
votes1
answer235
viewsA: Error using Qlabel - Pyqt5 class method
Qpixmap is from Qtgui: from PyQt5.QtGui import (QPixmap) ^^^^^^^ Even if used indirectly, Py needs the respective import. Pyqt is a wrapper for the implementation in C++, and needs to "know" the…
-
14
votes5
answers357
viewsA: How to dim the blue light on a website?
An extremely simple and at the same time objective way is to create an element that covers the viewport whole with opacity and blend-mode multiply. The multiplydoes exactly what we want, which is to…
-
10
votes4
answers11575
viewsA: Use . env file in PHP project?
Files with arbitrary extension Some systems/frameworks may elect text files with arbitrary extensions such as .env, .ini, .config and others, this does not make these archives anything special, it…
-
7
votes3
answers2842
viewsA: Swap the image on smaller screens
If it were in CSS, I would recommend a search by @media on the site, we have several examples, but as you want to change a content image, let’s go another way. In HTML5 you can do without relying on…
-
6
votes2
answers930
viewsA: Removal of excess whitespace
An alternative: Function MiddleTrim(cText) While " " $ cText cText = StrTran(cText, " ", " ") End Return AllTrim(cText) Remembering that although shorter than the @Maniero response (which already…
-
2
votes2
answers57
viewsA: How to keep the variable with the same value in the database?
One way is to generate your own query conditionally: // cria um array vazio. $campos = array(); // se houver algum valor em $nome, adiciona "nome='$nome'" em $campos if(!empty($nome)) $campos[] = "…
-
5
votes2
answers12373
viewsA: "perfect" square root in python and identify the rest:
To answer from Mr Anderson already took my +1, but only to complement follows an alternative without use of the module: import math value = 87 sqrt = int(math.sqrt(value)) remainder = value - (sqrt…
-
2
votes2
answers424
viewsA: move_uploaded_file only works once in the file
The move_uploaded_file is practically an operation only to "accept definitively" the upload taking from the temporary location (usually the TEMP or TMP of the file system itself) avoiding its…
-
2
votes1
answer286
viewsA: How to increment and decrease using FOR?
It’s basically a matter of scope. Just take out the variable declaration from the body of the function, see the code working just below by clicking on "run": var count = 0; // tiramos esta linha da…
-
6
votes2
answers9900
viewsA: Disable "sql-mode=only_full_group_by" option
The options to change SQL MODE are these: Using this on the command line when starting the server: --sql-mode="modes" Or in the configuration file: sql-mode="modes" In _Untime: SET GLOBAL sql_mode =…
-
4
votes1
answer110
viewsA: Error in "=" in mysqli_query
As resolved by @rray us comments, is syntax error. Foul $ in assignment (so that PHP knows that it is a variable): $result = mysqli_query("SELECT ... ^…
-
5
votes3
answers5999
viewsA: several values for a column in Where
The original query problem: First, your condition would always be false, you’d need a OR and ( ) if it were to maintain the same structure: where DepartureDate between '20161120' and '20161120' AND…
-
10
votes2
answers354
viewsA: Why does max not even min return the expected value?
Basically it’s a type error. A string 50 begins with "5" A string 100 begins with "1" Min and Max act alphabetically in strings. To test, change the query for this: SELECT MIN(0 + users_licensed)…
-
6
votes1
answer137
viewsA: How to make an appointment to get the dates according to the weekdays?
Just use WHERE DAYOFWEEK( data ) = dia_desejado The days of the week are numbered from 1 (Sunday) to 7 (Saturday). Applying to your case: SELECT campos FROM tabela WHERE DAYOFWEEK( data ) IN ( 1, 7…
-
13
votes1
answer188
viewsA: How to mark in bold triple and quadrupled sequential characters of a string?
PHP version $string = 'AAACDEAAAABBBUUDD'; $bold = preg_replace( '/(.)\1{2,}/', '<b>$0</b>' , $string ); See working on IDEONE Javascript version var str = "AAACDEAAAABBBUUDD"; var res =…