Posts by Bacco • 93,720 points
1,184 posts
-
8
votes2
answers13641
viewsA: Deletion of repeated words using Notepad++
If your Notepad++ has plugin Textfx (newer versions usually come with it. Alternatively you can easily add it using the Plugin manager), and the words are in separate lines, you can do this way:…
-
4
votes1
answer1395
viewsA: Sum of several text files *.txt
A relatively simple way is to use Windows CMD. Using for + type: cd /d c:\caminho\para\a\pasta for %f in (*.txt) do type "%f" >> amalgama.out in place of amalgama.out you put the desired…
-
3
votes1
answer236
viewsA: "Fine tuning" in SELECT for a ranking system
Missed the ORDER in the first SELECTs. ( SELECT nome_jogador, pontuacao FROM jogador WHERE pontuacao > (SELECT pontuacao FROM jogador WHERE id_jogador=4 ) ORDER BY pontuacao LIMIT 2 ) UNION (…
-
8
votes1
answer649
viewsA: When marking checkbox, leave visible link
Just a little CSS: .checkshow input[type="submit"] { opacity:0;transition:.5s;pointer-events:none } .checkshow input:checked ~ input[type="submit"] { opacity:1;pointer-events:auto } .checkshow…
-
5
votes1
answer74
viewsA: Would it be possible to identify 2 larger numbers in a sequence of 5 numbers typed by the user?
I think that’s enough: int maior1 = 0, maior2 = 0; for(int i = 0; i < 5; i++) { System.out.println(" Digite números:"); int num = sc.nextInt(); if(num > maior1) { maior2 = maior1; maior1 =…
-
9
votes2
answers2050
viewsA: How to show only "x" characters in a div?
Using CSS CSS doesn’t have a specific way to count "x" characters, but there are some things that can help you out a bit: overflow:hidden causes the content to be cut when it does not fit in a…
-
2
votes1
answer84
viewsA: How to do while in PDO and data manipulation?
Just add a [] in the $return: $return = array(); // Nem precisa desta linha, mas no mínimo fica mais fácil entender. while ($linhaMsg=$pegaMsgsLogra->fetch(PDO::FETCH_ASSOC)) { @$idAviso =…
-
8
votes3
answers241
viewsA: Condition within a . each()
You can use the module/split rest: $('li').each(function(index,value){ if((index%3)==0){ $(this).css('color','red'); } else if ((index%3)==1){ $(this).css('color','blue'); } else if ((index%3)==2){…
-
8
votes3
answers401
viewsA: How to create Mysql search that returns lines without matching?
Just use a LEFT JOIN, and check which relations return null: SELECT nome, filme_id FROM cliente LEFT JOIN aluguel ON cliente.cliente_id = aluguel.cliente_id WHERE aluguel.cliente_id IS NULL; See…
-
4
votes1
answer330
viewsA: Include in absolute address
This is probably what you’re looking for: include( $_SERVER['DOCUMENT_ROOT'] . '/config.php' ); So you have the absolute path of include in relation to the disk, and not to the website URL. If you…
-
4
votes2
answers1136
viewsA: How to make full-page vertical slides that roll with the mouse scroll?
I hitched a ride in this reply from Sozão, who already had the code ready. The example is in jQuery, but can do a good with pure Javascript (by the way, it is recommended, unless your site is…
-
6
votes2
answers5991
viewsA: BIT(1) versus TINYINT(1) for boolean values
The guy BIT was made with bitfields in mind, not "loose" bits. Not that you can’t save a single bit, but there’s no space saving in this case. A column BIT(1) will occupy one byte per row as well as…
-
7
votes2
answers333
viewsA: Equivalent Hide and CSS show
HTML + CSS solution Follow a CSS solution to show only one element at a time. You can test right here: #cards input { display:none; /* Vamos esconder os radiobuttons */ position:absolute; /* e tirar…
-
6
votes2
answers69
viewsA: IF to check quantity needed for given KG
I think it’s very simple, you can test it right here: function calc() { var peso = document.getElementById( 'peso' ).value; var b40 = Math.floor( peso / 40 ); var b3 = Math.ceil( ( peso - b40 * 40 )…
-
17
votes1
answer28766
viewsA: List files from a PHP folder / directory of certain extensions
Using your code: chdir( 'pasta_desejada' ); $arquivos = glob("{*.png,*.jpg,*.jpeg,*.bmp,*.gif}", GLOB_BRACE); foreach($arquivos as $img) echo $img; Using the standard functions for PHP directories:…
-
7
votes4
answers1852
viewsA: Reference of variable
Simplifying In this first case, the following happens: function bar($var) { $var++; return $var; } $b = 5; echo bar( $b ); // Mostra 6 - valor do return echo $b; // Mostra 5 - valor do $b is…
-
6
votes2
answers263
viewsA: How to prevent my site from being rendered in an iframe
Using Header Newer browsers accept an HTTP header for this purpose: X-Frame-Options Here are the options: deny - not allowed the Framing sameorigin - not allowed if not of the same origin allow-from…
-
3
votes2
answers121
viewsA: Create an array separated by date groups
Basically that’s all you need: $out = array(); $i = 0; foreach( $data as $item) $out[$item['data']][$i++] = $item; See working on IDEONE Applied to the code: $sql = $this->db->query($query) or…
-
6
votes2
answers72
viewsA: Insert multiple checkboxes into the Database
As you updated the question, it follows a small correction. You have to take the commas from the values, because the implode You’ll put them on, and name needs to be adjusted: <input…
-
18
votes5
answers42959
viewsA: Function equivalent to Trim (function to remove extra spaces at the beginning and end) in Python?
.strip According to the manual, there is the method .strip(): minhaString.strip() If you need to specify the characters to be removed, such as spaces only, leaving tabs and line breaks, you can use:…
-
5
votes1
answer493
viewsA: How do I pass this image as a parameter?
Pass as parameter was not the problem, but use the parameter. See the adjusted function: function muda_imagem(id, imagem) { document.getElementById(id).style.backgroundImage = 'url(' + imagem + ')';…
-
4
votes1
answer1434
viewsA: How to generate a "token" in the link bar with javascript?
Within what was asked, I think it solves: var result = ''; for (var i = 80; i > 0; --i) result += (Math.floor(Math.random()*256)).toString(16); document.getElementById( 'link' ).href +=…
javascriptanswered Bacco 93,720 -
4
votes2
answers758
viewsA: Php server check
For this, PHP has a native function, and a constant: echo php_uname(); // Sistema em execução no momento echo PHP_OS; // Sistema usado para BUILD do PHP See the format of the return: php_uname()…
-
2
votes2
answers209
viewsA: To highlight a line in the result of php+sql query
Only as a complement, an alternative with ternary operator: echo '</td><td>'; echo $array->usuario == $usuario ? '<strong>'.$usuario.'</strong>' : $usuario; echo…
-
7
votes3
answers6054
viewsA: How to concatenate HTML within PHP
In JS You can use both the concat as to the +: options.concat( '<option value="', j[i].CodCidade, '">', j[i].NomeCidade, ' ', j[i].ValorTarifa, '</option>' ); The Concat can be…
-
2
votes1
answer726
viewsA: Join with the same table more than once
Your query It took me a while to figure out what you wanted to do, but I guess that’s it: SELECT `tbl_operacao`.`id`, `tbl_operacao`.`tipo_operacao`, `tbl_imovel`.`descricao`,…
-
14
votes2
answers7415
viewsA: Why use error_reporting with display_errors and display_startup_errors?
display_errors The directive display_errors simply is an on-off of error display in script output. This directive does not change what is saved in PHP logs. It only changes the generated output. The…
-
4
votes1
answer675
viewsA: Save a website image with PHP?
His attempt with file_get_contents only works if the php.ini is set this way: allow_url_fopen=true But if you’re qualified, you don’t even need file_get_contents, can already simplify with copy:…
-
6
votes3
answers3146
viewsA: Tag <img>. When loading an image from the bank it appears lying down
Usually the photo was taken "lying down", and the correct orientation marked on the tag orientation of EXIF. The problem is that the photo is actually recorded "lying down" depending on the device…
-
3
votes2
answers452
views -
1
votes1
answer288
views -
4
votes2
answers75
viewsA: How to fix these styles to circumvent reported error?
Using radio Buttons If you want the 3+ click to include all the previous ones, the ideal is not to use checkbox, but yes radio button, because the semantics of checkbox is an independent selection.…
-
6
votes2
answers706
viewsA: How to toggle images when clicking a checkbox?
Image exchange technique using pure CSS: Here is a simple example to demonstrate the technique of background image exchange based on the attribute checked: input { visibility: hidden; } label {…
-
7
votes1
answer399
viewsA: How to export a Datatable to Excel without formatting the information?
Prefix the data with a single quote ' on export. For Excel, a data prefixed by ' is interpreted as text, and will not be formatted or interpreted. A single quote, when in the first character, does…
-
4
votes1
answer113
viewsA: Why are the data disappearing by refreshing this page?
Logical error. You are only recovering the SESSION if there is POST in your code. The correct part is just the $_POST part within the if, the rest off: if(isset($_POST['busca-implacavel'])) { if(…
-
5
votes2
answers785
viewsA: How to persist $_SESSION value in <select> as it was done for <input>?
If I understand the question, it’s more or less that: <?php $s = ' selected="selected" '; $nome = isset( $_SESSION['nome'] ) ? $_SESSION['nome'] : ''; $tipo = isset( $_SESSION['tipo'] ) ?…
-
7
votes3
answers825
viewsA: Make the page refresh and the message appear next
I already gave +1 in the answer of Pro Hands, because I think it will be difficult to have simpler and objective solution than this. I only posted a variant, so that it is clear to the author of the…
-
2
votes2
answers65
viewsA: Get records from 3 tables with JOIN
Probably just missing GROUP BY: SELECT u.login, SUM( c.quantidade ) AS qtd, SUM( f.status ) AS qtdF FROM usuarios AS u LEFT JOIN cotas AS c ON c.id_user = u.id LEFT JOIN faturas AS f ON f.id_user =…
-
4
votes1
answer1119
viewsA: Write Mil e Milhoes in PHP number
If not for currency values, this has already been posted here: How to convert number to number in spellnumber in PHP? Function ready for financial values: Source:…
-
4
votes4
answers1844
viewsA: Generate new name for image during upload - php
Just change these lines: $file = $uploaddir . basename($_FILES['uploadfile']['name']); $imvfoto = $_FILES['uploadfile']['name']; for $imvfoto = "o nome que você quiser"; $file = $uploaddir .…
-
10
votes1
answer10706
views -
4
votes3
answers447
viewsA: Divide a date into two parts
I would store with 2 fields. data, field date same (or int counting number of days of a standard date). periodo field int 1 byte only, or enum being: 1 = morning 2 = late 3 = both periods Thus…
-
2
votes2
answers432
viewsA: How do I compare a Session?
Follow a refactoring suggestion: session_start(); if ( isset( $_SESSION['clienteId'] ) && $_SESSION['clienteId'] > 0 ) { echo '<div class="verdinho">você está logado</div>';…
-
5
votes5
answers1021
viewsA: Pick first name with Regular Expression
You asked with regular expression, but I’ll leave some alternatives with operation string, if someone prefers without Regex (in fact, Regex is not for these simple things). Explodes $tokens =…
-
6
votes4
answers1125
viewsA: Run PHP function to insert data into DB daily at specific times
This is a very simple but fully functional way for this type of problem: create a field proximaexecucao in your DB agenda table In PHP you will use the following algorithm: if the current date/time…
-
3
votes3
answers408
views -
20
votes4
answers1239
viewsA: Format city names and ignore words like "do", "dos", "das", "da", etc
A sketch that can be easily adapted: function properCase( $string ) { $ignorar = array( 'do', 'dos', 'da', 'das', 'de' ); $array = explode(' ', strtolower( $string ) ); $out = ''; foreach ($array as…
-
7
votes2
answers294
viewsA: What is the correct way to return a "switch" value?
For the specific case of your code, with only two options, it wouldn’t make much sense to use switch. A single line with ? : (ternary) would suffice: $("#OcorrenciaStatus").html( ocoStatus == 'C'?…
-
3
votes1
answer48
viewsA: How to re-assign the ID colunda again?
If you want a sequential numbering, you don’t need to change the Ids, just use a counter: SELECT @linha := @linha + 1 AS contador, tabela_desejada.* FROM (SELECT @linha := 0) AS nada,…
-
4
votes4
answers1229
viewsA: Is there any way to display the result of a query(mysqli) in the form of HTML?
Complete HTML table If you want to display all data from a table, regardless of the query, has this more elaborate solution, which shows the results in table format, with the field names including:…