Posts by Bacco • 93,720 points
1,184 posts
-
5
votes1
answer893
viewsA: File Exists PHP
Trickster of the rascal 1: The function file_exists(), despite the name, checks if the path exists, regardless of whether it is a file or directory. When you leave the parameter empty, your test is…
-
6
votes3
answers1160
viewsA: How to set number of times the setInterval will be executed?
The @Sergio reply answers exactly what was asked, but is as a complementary suggestion setTimeout, which may be more interesting than the setInterval in your specific case, and simplifies the…
-
14
votes5
answers11978
viewsA: How to get the current file name
I think the simplest thing is this: <?php basename( __FILE__ ); ?> Alternative, which gives even more information: <?php $path_parts = pathinfo( __FILE__ ); echo $path_parts['basename'];…
-
12
votes1
answer310
viewsA: How to make a counter with zero left
Just use str_pad: for($i = 1; $i < 10000; $i++){ echo str_pad( $i, 5, '0', STR_PAD_LEFT ) . "\n"; } Upshot: 00001 00002 00003 00004 00005 ⋮ See working on IDEONE. Parameters: input value, desired…
-
18
votes2
answers52864
viewsA: How to check if the Term is contained in String in PHP?
Just use the function strpos (or mb_strpos for strings non-sascii): $palheiro = 'canais,proteses,implantes'; $agulha = 'proteses'; $pos = strpos( $palheiro, $agulha ); // exemplo de uso: if ($pos…
-
11
votes3
answers156
viewsA: Regular expression to reorder string
Alternate version, without Regex Not as an answer to the main problem, but as an alternative for other users who need to parse of strings in this format, follows a solution without Regex: $in =…
-
6
votes2
answers861
viewsA: How to generate code before entering data into the database
Follows the query to get the next ID: SELECT AUTO_INCREMENT FROM information_schema.tables WHERE table_name = 'nome_da_tabela' AND table_schema = DATABASE(); Or one of these: SHOW TABLE STATUS FROM…
-
4
votes2
answers522
viewsA: How to click and scroll a hidden part?
Alternative with CSS3 To whom interested can, follows a version that makes the proposed, but without using Javascript: #slideout label { position: absolute; top: 2px; left: 75px; width: 150px;…
-
9
votes3
answers170
viewsA: Create markup with predefined symbols
I’m posting as a separate response because the other’s JS has reached the Sopt character limit For mathematics: Two interesting projects are the Mathjax and the Asciimathml, incorporated in the…
-
7
votes3
answers170
viewsA: Create markup with predefined symbols
As you did not specify many details in the question, follow a "generic answer": Yes, it is possible and there are already several things ready in this sense. For example, the Strapdown does in JS…
-
11
votes2
answers910
viewsA: Count the amount of characters changed in an input field
To Distance from Levenshtein is one of the best known algorithms to calculate the difference between two strings. See an adaptation of another issue for your specific case: function…
-
4
votes4
answers9178
viewsA: Regex to pick a text between <>
Alternative solution (without Regex) As the author mentioned being using Java, there is an alternative answer with substring, for those who might be interested: mail =…
-
8
votes2
answers2406
viewsA: Transparent gradient superimposing <div> without losing the "click"
Click problem not being blocked by gradient can be solved in some browsers with CSS: pointer-events: none however, to make a version quite compatible, you may need some JS per warranty if you want…
-
5
votes3
answers5031
viewsA: Error formatting ZIP code
The problem is in your Regex: /^([\d]{2})([\d]{3})([\d]{3})|^[\d]{2}.[\d]{3}-[\d]{3}/ When there are only digits, the capture groups $1, $2 and $3 are taken by the parentheses, in condition before…
javascriptanswered Bacco 93,720 -
6
votes1
answer332
viewsA: Find the least-appearing numbers in the records
I will divide logic into separate steps to facilitate. First, let’s see where was the last occurrence of number 21, for example: SELECT reg FROM tabelaMaisOuMenosAssim WHERE 21 IN…
-
6
votes3
answers4269
viewsA: Detect browser language and redirect
This solution posed in the question does not go very well by the way in which the HTTP_ACCEPT_LANGUAGE works. It returns a string in this format: en-US,en;q=0.8,pt-BR;q=0.6,pt;q=0.4 indicating the…
-
14
votes4
answers732
viewsA: How to create a function to scroll through a dynamically created PHP page and change certain text
Initial idea: I used a small text, but this fits perfectly for a full HTML page. It follows a sketch of what you can do, in a very simple way: $oa = ( $sexo == "feminino" )? 'a':'o'; $texto = "Olá,…
-
2
votes1
answer72
viewsA: Format string Qt html charset
There is no specific method in Qt to decode entities, but an outline is to use QTextDocument *texto= new QTextDocument(); texto->setHtml( "Macarrão integral<br>" ); and take…
-
6
votes1
answer79
viewsA: Problem with Regular Expression
Just add parentheses in the search for anexo: /[a-z]{3}_(ANEXO|Anexo|anexo)_[A-Za-z]{1,7}_[A-Z]{1}_[A-Z0-9]{2,5}....pdf/ Test in Regex101. More complete solution, providing the brackets: The user…
-
8
votes2
answers958
viewsA: Take a line ID that has just been created in PHP
If you are using the Mysqli extension: mysqli_query( $con,"INSERT INTO jogadores(nome, idade) VALUES ('Pedro',35)" ); $id = mysqli_insert_id( $con ); // Aqui obtemos o ID do registro inserido For…
-
7
votes1
answer1176
viewsA: Javascript function that generates html colors according to value
I created this basic function, which perhaps meets your need: function colorTween(c1,c2,p) { var r1 = parseInt(c1.substring(1,3),16); var g1 = parseInt(c1.substring(3,5),16); var b1 =…
-
5
votes1
answer545
viewsA: How to use a Function inside another Function in php?
To use the function created by you, just use it in the same way as any pre-existing one in PHP: function usuarios(){ // listando usuarios $datacadastro = formata_data("Y-m-d H:i:s"); } However, your…
-
6
votes3
answers1488
viewsA: Cut text and add ellipsis
Here is a possibility in PHP, based in another answer: $tamanho = 300; $pos = strrpos( $texto.' ', ' ', $tamanho ); $retorno = substr( $texto, 0, $pos - 1 ); if ( $pos < strlen( $texto ) )…
-
3
votes1
answer79
viewsA: Leave the bar centered using dragdealer.js
Just use the method setValue to specify the desired initial value. See function with some optimizations: d = new Dragdealer('just-a-slider', { animationCallback: function(x, y) {…
-
3
votes1
answer159
viewsA: Graphic made with imperfection Javascript canvas
The ideal would be to use the property width and height instead of clientWidth and clientHeight: window.onload = function () { var contex = document.getElementById("grafico").getContext("2d");…
-
2
votes2
answers1384
viewsA: Sort by day of the week starting by today
A very simple way is this: SELECT * FROM tabela ORDER BY ( FIELD(day, 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') - DAYOFWEEK( CURRENT_DATE ) + 7 ) % 7 so the query…
-
2
votes1
answer27
viewsA: Is it possible to use IGNORE based on a field that is not PK, it is only a Single Index?
No problem to use IGNOREin any single key, the effect is the same. the IGNORE acts on both PK violations and other constraints, like UNIQUE. So much so that you can use INSERT IGNORE if your table…
-
5
votes1
answer199
viewsA: Function file() php does not pick line by line
There is a directive in PHP for automatic line break type detection: auto_detect_line_endings Use: <?php ini_set("auto_detect_line_endings", true); $lines = file("NET3110123.txt"); foreach($lines…
-
2
votes1
answer84
viewsA: Set mysql variable with the name {parametro1}
After spending a few seconds doing a test, I got the following answer: Yes, it is possible The test: set @'{banana}' = 10; select @'{banana}' The result: 10 See the test done and running online on…
-
4
votes1
answer141
viewsA: DEFAULT CURRENT_TIMESTAMP
To update both the Insert and the update, both declarations are required: DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP More details on manual.…
-
4
votes4
answers814
viewsA: Repeat alphabet similar to excel columns
Follow a formula where you pass the column number, and get the corresponding string. Can be used to get any column, no need to calculate the previous ones. It’s an interesting add-on to @rray’s…
-
2
votes2
answers132
viewsA: Problem with second degree equation program
Follow an alternative to @Samuelgomes code, with the rounding problem solved with the removal of the sqrt: #include <stdio.h> int main (void) { int n1, n2, n3, t; scanf("%d", &n1);…
-
5
votes1
answer137
viewsA: Encoding and decoding passwords with character rotation
As I mentioned in the comments, to rotate the characters "up" and "down" alternately, this code is enough: String s = "ABCDEmasterbbbbbbb123"; int j = -1; for (int i = 0; i < s.length(); i++) {…
-
3
votes1
answer682
viewsA: Modal window "once per session"
Using Jquery with a plugin to work with cookies we can reach the desired result: Link to the plugin: http://plugins.jquery.com/cookie/ Example of application in your code:…
-
4
votes2
answers559
viewsA: Sum of values in variable does not occur, tofixed
The problem is that you are concatenating strings, (return from toFixed) and not adding up numbers: var x = 0; x = parseFloat((x + 0.4)).toFixed(1); // "0.4" <-saída verdadeira x = parseFloat((x…
javascriptanswered Bacco 93,720 -
5
votes3
answers14735
viewsA: How to break a line of a Mysql field into an HTML page
Just store the line breaks: UPDATE tabela SET campo = CONCAT( "0 anos,", CHAR(10), "3 dias ) Note that the desired break depends on a number of factors: UPDATE tabela SET campo = CONCAT( "0 anos,",…
-
6
votes4
answers10317
viewsA: How to delete files inside a folder
Here is a ready-made function, posted on the PHP website <?php /** * Recursively delete a directory * * @param string $dir Nome do diretório * @param boolean $deleteRootToo Ponha True se quiser…
-
1
votes2
answers86
viewsA: PHP Submit refers to the wrong file
I agree with @Zuul that the ideal is not to use JS unnecessarily, as in this case. Anyway, a simple adjustment to the Submit function can help: // Adicionamos o parametro "meuForm" na funcao…
-
3
votes2
answers1775
viewsA: batch file to create mysql database
The syntax for using an SQL command on the same line is this: mysql --execute="statement" mysql -e "statement" In your case: mysql.exe -u root -proot -e "CREATE DATABASE BDNAME" (or you can simply…
-
3
votes3
answers458
viewsA: Search database table information with PHP every 10 minutes
The obvious means is to create an entry in the crontab or in the task scheduler run the desired PHP every 10 minutes. Linux In most distros *Nix the crontab line would look like this, to run every…
-
5
votes1
answer76
viewsA: Open disk player with Java, and without specifying the drive
Not directly in Java, but these alternatives can be called as external application using exec(): Script taken from Sozão, for Windows, command-line + Vbscript. Save as batch (.bat) itself calls the…
-
2
votes1
answer889
viewsA: Catch field on table with Mysqli
Just fixing what you asked for would be something like this: function confirmaPedido ( $conexao, $numeroPedido, $senha ) { $resultado = mysqli_query( $conexao, "SELECT senha FROM adm WHERE senha =…
-
4
votes3
answers1346
viewsA: How to replace all attributes using jQuery/Javascript?
Using Jquery: var num = 1; var clone = $('.form-modelo').clone(); clone.attr('class', 'form-real'); clone.children().each( function() { $(this).attr('id', $(this).attr('id').replace( /__prefix__/,…
-
11
votes1
answer129
views -
3
votes1
answer73
viewsA: problems when updating a table
I would suggest changing this line: "<td><input type='button' value='Update' class='btn-update' data-id='".$valor['ID']."'>"."</td>" for this: "<td><input type='button'…
-
19
votes3
answers2689
viewsA: How to rename all tables in a Mysql database
To rename a table, you use the command RENAME TABLE nomeOriginal TO nomeNovo As there are many tables, you can use this query to generate all RENAMEs automatically: SELECT CONCAT( 'RENAME TABLE `',…
-
5
votes5
answers1617
views -
2
votes1
answer55
viewsA: Creation of links with image
There are several ways to create an image link. The difference depends on the context and semantics to be used. See the most common ways: Pure HTML If the image is part of the page context (not just…
-
1
votes1
answer231
viewsA: Problem with delta output<0
Just the part you posted about the code, it’s hard to help. The impression is that one is missing else to display results only if delta is zero or more. Something like that: if (delta<0)…
-
6
votes2
answers331
viewsA: Check string value
I imagine that it is a school exercise or something like, after all, present options for user choice textual way is not usually ideal for practical use. As the question problem has already been…