Posts by Bacco • 93,720 points
1,184 posts
-
4
votes4
answers2570
viewsA: How to take the penultimate and antipenultímo item from an array
Some more alternatives: $array = ['um', 'dois', 'tres', 'quatro', 'cinco', 'seis']; $ultimoAntepenultimo = array_splice( $array, -3, 2 ); (use the slice in place of splice if you don’t want to…
-
8
votes1
answer540
viewsA: Delete item from an array and reorder it - PHP
Answering the question ... Whenever you want to ignore the keys of an array, just use the function: array_values ( array $input ): array Demonstrating in your code: $array = [ 0 => 'Fellipe', 1…
-
3
votes1
answer491
viewsA: Group Mysql output in PHP
To group multiple lines separating by comma, you can use the GROUP_CONCAT SELECT usr.id, GROUP_CONCAT( aut.marca ), GROUP_CONCAT( aut.modelo ), GROUP_CONCAT( aut.ano ), usr.nome_completo, usr.rg…
-
7
votes1
answer601
viewsA: Mysql function to return text according to numeric index
Two solutions with Mysql: Function ELT() SELECT ELT( tipo, 'administrador', 'usuario', 'cliente'); ELT returns the string of the position indicated by the first parameter, in the case of the column…
-
14
votes2
answers766
viewsA: How to humanize a date in PHP
Following the same principle of this post, can from this code: function RelativeTimeString($timestamp) { $minute = 60; $hour = $minute * 60; $day = $hour * 24; $month = 30 * $day; $year = 12 *…
-
8
votes2
answers4388
viewsA: Error creating table: Invalid default value for
According to the manual: As of Mysql 5.6.5, TIMESTAMP and DATETIME Columns can be Automatically initializated and updated to the Current date and time (that is, the Current timestamp). Before 5.6.5,…
-
3
votes1
answer401
viewsA: Count record of two date fields grouping by year
As you are grouping by different columns, you need to treat the darlings separately. We can start from the query simple, based on its: SELECT YEAR( inicio_contrato ) AS ano, COUNT( * ) AS contagem…
-
6
votes1
answer386
viewsA: Help with 16bit Hexadecimal RGB colors
Most likely the color palette is reduced (may be related to the video processor used, or simply be a compact way to store the data). In this case, being 5 bits per color (from 0 to 31) they can be…
-
7
votes1
answer58
viewsA: How can I make a program that answers a mathematical formula?
I don’t know which formula interests you, but see if anything helps: var numero = 1230; // se quiser numero/360 = resultado var resultado1 = Math.round( numero / 360 ); // se quiser resultado/360 =…
javascriptanswered Bacco 93,720 -
12
votes3
answers327
viewsA: Query to get 1024 sum in maximum 3 transactions
One way to organize the problem is to start with the higher values. If the first three values do not meet the requested condition, surely lower values will also not meet. Organizing the data…
-
7
votes2
answers4183
viewsA: How to discover a collation of a table or database using an SQL query?
That’s all it takes: SHOW CREATE TABLE nomedatabela And from the database: SHOW CREATE DATABASE Syntax The way out is something like that: CREATE TABLE `t` ( `id` int(11) NOT NULL AUTO_INCREMENT,…
-
9
votes1
answer2032
viewsA: What are the ways to create html file using php?
One of the quick ways to take advantage of an existing PHP is this: <?php ob_start(); // Isto bloqueia a saida do PHP para a "tela" ... tudo que você faria normalmente no PHP $gerado =…
-
5
votes1
answer143
viewsA: Verify serial compliant date
If you want to know the date, that’s all it takes: function VencimentoSerial($serial) { $vencto = strtotime( '2016-1-1 +'.hexdec(substr($serial, 3, 2)).' months last day'); return gmdate( 'd/m/Y',…
-
5
votes1
answer96
viewsA: Sort records containing numbers at the end
It would probably be the case to rethink the organization of DB, perhaps separating this information into two parts (storing only the number, if the rest repeats) or storing in separate columns. You…
-
55
votes3
answers3408
viewsA: How to find out if a hexadecimal color is dark or light?
Calculating luminosity The solution comes from W3 itself: https://www.w3.org/TR/AERT#color-Contrast More specifically with this formula: ( R * 299 + G * 587 + B * 114) / 1000 It returns the…
-
3
votes1
answer282
viewsA: Automatic download of data from an ftp address
You are putting the URL in place of the username. Note that the URL is repeated. If you used variable substitution, you put the wrong variable. Also, the actual URL construction is wrong. Instead:…
-
4
votes2
answers531
viewsA: Mysql Auto increment even number
This is a basic configuration, commonly used when you have Dbs divided into more than one machine (so that they can be joined without conflict, or for identification of the machine responsible for…
-
4
votes1
answer197
viewsA: REPLACE in the IN - Mysql clause
Basically it’s a syntax problem. You said if you do it "in hand" it works: catcar.IdCategoria IN ('10, 11, 29, 30, 31') Works only if idcategoria be exactly the string 10, 11, 29, 30, 31, after all…
-
3
votes1
answer385
viewsA: Select with subquery turning into column
You can make a conditional sum with if: SELECT nomealuno SUM(IF(idavaliacao=1,nota,0)) AS trabalho, SUM(IF(idavaliacao=2,nota,0)) AS prova FROM tblaluno a LEFT JOIN tblnotadisciplina b ON…
-
9
votes1
answer84
viewsA: How to convert NFA to datatime and vice versa?
This format you put in the question stores the time in the last five hexadecimal digits, and the rest is the date (both with an adjustment factor). You can make a conversion from NFA to timestamp…
-
6
votes1
answer2359
viewsA: Perform direct calculations in the sql query
No problem doing the operations in SQL SELECT SUM(valor) AS totalvalor, SUM(juros) AS totaljuros, SUM(multa) AS totalmulta, SUM(desconto) AS totaldesconto, SUM(valor + juros + multa - desconto) AS…
-
12
votes2
answers206
viewsA: Is it possible to optimize this javascript code?
Instead of changing a mask with the pin in each position, we can rethink logic and use the same image in different positions. The marker (pin) Let’s start with the pin: If we put the pin within a…
javascriptanswered Bacco 93,720 -
7
votes1
answer206
viewsA: What mysql.sys do?
Since Mysql 5.7.7, Schema to facilitate performance statistics managed by engine PERFORMANCE_SCHEMA, and he is just the sys. This user has also been created (called DEFINER in this context):…
-
12
votes1
answer794
viewsA: How to use "Count se" in PHP
If you REALLY want to count in PHP you will need something like this: $row = $data->fetchAll(); $i = 0; foreach($row as $item) { if( $item['status'] === 1 ) ++$i; // ^^^^^^^^^^^^^^^^^^^^^ aqui…
-
6
votes1
answer1181
viewsA: Table size does not decrease
When you delete a record, you are simply warning that that space is free. It would be impractical for a DB to keep shortening the file in production as this would mean rearranging all the data…
-
4
votes4
answers3595
viewsA: How to put picture in input type reset?
Using Label Almost all form controls can have a "shortcut" with a label: #r {display:none} #l { display:block; width:32px; height:32px; background:url(https://i.stack.imgur.com/OV6nj.jpg?s=32) }…
-
9
votes2
answers1746
viewsA: How do you count the number of times a word repeats itself in a sentence?
PHP already has a function ready for this: $ack = "Você tem que abrir seu coração pro SQL e pedir o que realmente quer."; echo substr_count ( $ack, 'que' ); See working on IDEONE. If you don’t want…
-
9
votes3
answers129
viewsA: Split a string that contains scores
If it were just spaces, it would be a case of $partes = explode( ' ', $todo ); A solution, depending on what you want, would be to force a space before the characters you want to treat as isolated:…
-
9
votes2
answers1527
viewsA: How to search for saved records in the current week?
If you were to compare whether two arbitrary dates are in the same week: SELECT campos FROM tabela WHERE DATE_SUB(data1, INTERVAL DAYOFWEEK(data1)-1 DAY) = DATE_SUB(data2, INTERVAL…
-
3
votes2
answers597
viewsA: Rename files with random names using php
Basically this: foreach (glob("*.gif") as $arquivo) { $nome = substr(hash('md5',time().rand()),0,10); rename($arquivo, $nome.'.gif'); } we passed the generation of the name to the loop, so that it…
-
5
votes1
answer74
viewsA: Other Type of checkbox
Assuming I have understood right, which is to change the value just by clicking, you can do something very practical with Javascript: function spin(element,delta,max) { var input =…
-
18
votes1
answer719
viewsA: How to get only the domain of a URL?
PHP already has a function that separates all elements of a URL. Is just the parse_url: $url = 'http://exemplo.com/pasta/pasta2/past/ficheiro.php'; $elementos = parse_url($url); echo…
-
5
votes3
answers522
viewsA: Regular expression, PHP
Basically this: /filmes/todos-filmes/notas-espectadores/\?page=\d+ The backslash before the ? is because of ? alone be a special character. The \d means "digit", and the + then means "one or more",…
-
3
votes1
answer54
viewsA: Does not enter the if
Tested with spaces in string, it’s not to come in at all. ' AND' and 'AND' are separate things. One solution would be this: if (!strcmp(trim($value), 'AND') || !strcmp(trim($value), 'OR')) { Here…
-
4
votes3
answers491
viewsA: How can I make a select and turn it into an array
Gonçalo, I took as a basis the gonçalo’s answer but simplified the loop: $postos = array(); while($array1 = mysqli_fetch_array($procura1)) $postos[] = $array1['posto']; This works because when you…
-
7
votes2
answers973
viewsA: How to make this slideshow infinite?
As it is "rotating infinity", it has to completely eliminate the movement of the "rail": In the HTML and CSS part we gave a "dry" eliminating unnecessary elements, taking advantage of these…
-
6
votes1
answer105
viewsA: Error in HTML Slider
The problem there is a mixture of quotes in the same HTML part. A simpler way is to close PHP to fall into pure HTML mode, so you can use single double quotes to separate HTML parameters from JS…
-
7
votes1
answer518
viewsA: What is a Binary-safe function? And what are its applications?
Basically it means that it will work with any sequence of bytes. If you put control characters, "\n", or null character "\0", she won’t have any trouble making the replacement. Example: $str1 =…
-
4
votes2
answers1982
viewsA: How do I find out the current version of codeigniter?
Just use the defines built in: define('CI_VERSION', '2.2.3'); Which in version 3 is defined as const CI_VERSION = '3.2.0-dev'; This is in /system/core/CodeIgniter.php…
codeigniteranswered Bacco 93,720 -
4
votes2
answers1361
viewsA: Display only one record with foreach
If you want one, you don’t need foreach, just pick up the index: <?php $posts = DBRead('posts', "WHERE categoria = 3 AND status = 1 ORDER BY data_numero ASC"); if( !$posts ) { echo…
-
5
votes1
answer186
viewsA: Different concatenation ?
Concatenation is simple, just use the +, which is contextual (numerical sum and concatenate strings). To make life easier, it’s interesting to use a id in the elements: <label…
-
3
votes1
answer190
viewsA: Chosen Jquery: remove selection by typing DEL
You can make an external script for this, or a tag script at your convenience: $("#foco")[0].addEventListener('keyup',function(e) { if (e.keyCode == 46) {…
-
3
votes1
answer1810
viewsA: How to confirm the PDO UPDATE
You can use the rowCount: $stmt->rowCount(); When you make a SELECT, it returns the amount of results, but when it does UPDATE, DELETE etc it returns the number of affected lines. if(…
-
10
votes5
answers4393
viewsA: Transforming a JSON information into a variable
Complementing existing responses if you have a string and not an object, can convert with JSON.parse: var str = '{ "pair": "BTCBRL", "last": 2280.0, "high": 2306.0, "low": 2205.0, "vol":…
-
6
votes5
answers14273
views -
5
votes1
answer1234
viewsA: Inner John repeating data
The JOIN relates two tables, relating the data as if it were all part of a single table, composed of the two. Here’s a good explanation of how it works: What is the difference between INNER JOIN and…
-
4
votes1
answer44
viewsA: Why does this compressed css code stop working?
The problem is that the applied compression criterion moved where it shouldn’t. That one: font:"0/0" a was improperly converted to font:0/0 a breaking the whole set. See your code with the removal…
-
7
votes3
answers72
viewsA: Javascript Doubt ( Loopin through an array using a for loop )
Here is created an empty paragraph in HTML, and given a id to him: <p id="demo"></p> On the part of script, in Javascript an object is created. An object can have a list of values,…
javascriptanswered Bacco 93,720 -
5
votes1
answer47
viewsA: Explain Line of Code (You can loop through Object properties by using the for-in loop)
As you saw in the previous question, document.getElementById("demo") to recover from DOM (the page structure, mounted according to HTML) an element defined by id="demo". Then the .innerHTML…
javascriptanswered Bacco 93,720 -
9
votes2
answers11695
viewsA: Definition : Document.getElementById
About the getElementById Basically the document.getElementById, as the name already says, it is a Javascript function that serves to return a DOM element that is identified by a specific ID. See the…
javascriptanswered Bacco 93,720