Posts by Bacco • 93,720 points
1,184 posts
-
7
votes4
answers30006
viewsA: Limit text display in PHP
The most universal solution is this: mb_substr ( string $str , int $start , [ int $length [, string $encoding ]] ) The function substr is limited to encodings single byte, and will have problems…
-
8
votes1
answer350
viewsA: How getTime works
The measure is in thousandths of a second. Looking at that expression, you can see they were originally days * 24 and not 2. date.setTime(date.getTime()+(days*24*60*60*1000)); └─────┬──────┘…
-
2
votes2
answers103
viewsA: data conversion problems with php
Rethinking the code: In case you use the Runtime version, date_default_timezone_set, call it BEFORE using the date functions. At the beginning of the code that calls the function, and not inside it.…
-
6
votes1
answer283
viewsA: How to set height in percentage using css
To use measurements relative to the displayed area, use vw and vh. See that the example in yellow is related to the area of the frame (viewport width and viewport height). Click on whole page right…
-
4
votes1
answer644
viewsA: Incomplete Edge
Natively there is no way to change the "size" of each border, but you can simulate with pseudoelements: div { position:relative; border-bottom:1px solid #000; /* borda inteira de baixo */…
-
3
votes1
answer1544
viewsA: The process cannot access the file because it is being used by another process
If the code is only this one, it is a typo. See the difference in the variables LJ1 and LJ2: string CJ; string CJ1; string CJ2; StreamReader LJ = new StreamReader(Application.StartupPath + @"\Jo\" +…
-
0
votes3
answers93
viewsA: Join with two tables and a varchar2 field
To filter a result by a condition outside the JOIN is used WHERE. Taking advantage, you can simplify so: SELECT * FROM cidade AS c, estado AS e WHERE e.id_estado=c.fk_id_cidade AND…
-
8
votes1
answer67
views -
8
votes6
answers4503
viewsA: If null, Nan, false and Undefined in Javascript
Usually a simple if(variable) is used to determine any of the situations in code, but to detect each situation individually follows a summary: Testing if it is null: if( minhaVariavel === null ) ...…
javascriptanswered Bacco 93,720 -
1
votes1
answer183
viewsA: Two php foreachs - Duplicate data
One of the most practical ways without changing your code too much is to use a single loop, and use the index in arrays originals: <?php $count = count($contratantes); for($i = 0; $i < $count;…
-
3
votes1
answer384
viewsA: Problems with file_put_contents()
If you don’t really need to make a disk cache, it’s much easier to use a simple echo, and write the file itself as events.json.php : $servicos = $db->prepare('SELECT id_servico,…
-
1
votes1
answer100
viewsA: Do Not Repeat Values
The problem is that you are overwriting the variable in loop. A solution would be to store the name in each marker: marker.contentString = cord[i].local; And reclaim the value with this:…
-
10
votes1
answer688
viewsA: Color generator
A very simple way is this: RGB(RandomRange(150,255), RandomRange(150,255), RandomRange(150,255)); Basically you’re making the minimum color 150, 150, 150. The higher the value, the lighter the…
-
9
votes1
answer4278
viewsA: How does Session’s duration work?
The session in PHP consists of a cookie with an identifier, and a server-side cleaning system. Client side The time of cookie of the current session from the beginning this, and even if the person…
-
3
votes2
answers25262
viewsA: Remove edge that separates columns from a table
First of all, you need to fix your HTML, because you are putting tr inside td, closing thing that didn’t open, and other little problems. Once we’ve solved the code, we’ll go to the edges: If HTML5,…
-
8
votes1
answer11869
viewsA: Placing html code inside php
The problem is that this line here: <?php while($dado = $con->fetch_array()){ ?> is inside a HEREDOC, so it is treated as text, not PHP. The solution without touching your code too much is…
-
3
votes1
answer32
viewsA: Multiply table prefixes
Has this: str_replace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] ) Applying to your case: ->from ( str_replace( '#_', 'Test', '#__dolar_corrent AS a' ) ) etc If you…
-
5
votes1
answer251
viewsA: Difference between dates in Months for range >= 12
You don’t need workaround, just add 12 months to each year. return $interval->m + $interval->y * 12; See working on IDEONE.…
-
5
votes2
answers686
viewsA: Change position image with transition when mouse over it?
Float is not "spirited", but you can achieve something of the kind by using absolute position and varying the left: #area { position:relative; overflow:auto; } #area img { display:block;…
-
6
votes1
answer104
viewsA: How to generate a graph with a curve similar to "sine" in jquery Flot?
In principle, what you’re looking for is an envelope, to modify the main wave. To simplify things, you can create a function that takes a linear value, and turns it into a curve. Here’s a simple…
-
7
votes1
answer69
viewsA: Can anyone help me fix this Javascript?
Missing a comma after dataType: 'json', Missing one n in the ready:function(){ On line 21 this here is the most: }}; The correct nesting can not know, depends on the end of the code. Understand that…
-
5
votes1
answer38
viewsA: How to return the expected result in this query?
Your current condition can be divided into these two parts: 1: Hacker And Automobiles OR 2: Food Actually, what you want is this: 1: Hacker And 2: Automobiles OR Food So, you need to parentheses in…
-
5
votes1
answer73
viewsA: What’s unscathed for python?
Are you comparing string with float after the first iteration. The solution is to convert the extracted text always to float: price = float( text[preçoinicial:preçofinal] ) ^^^^^ Thus remaining:…
python-3.xanswered Bacco 93,720 -
2
votes1
answer339
viewsA: Posting system duplicating posts - PHP
You are doing the select at the beginning of the code, before inserting the new post, then the new post has no way to even appear, because when it is inserted, you have already taken the listing…
-
5
votes1
answer1420
viewsA: do the multiplication of values using sum operator and while
If we take 5 x 7, that gives 35, we can see this way: 7 + 7 + 7 + 7 + 7 n2 └────────┬────────┘ 5 n1 Transporting this to an algorithm means we have to add the value n2 (7, in the example) for n1…
-
5
votes1
answer1061
viewsA: input:checked is not applying the properties
The problem is that the selector ~ refers to an element that is preceded by another within the same "parent" of the tree structure of the file, and is not the case for its HTML. Of W3C…
-
7
votes1
answer411
viewsA: What language is used in the Apache ". htaccess" file?
In a nutshell, it is a specific "language" for configuring Apache that does not have an explicit name in the documentation, nor is it restricted to .htaccess. It is a collection of directives which…
-
5
votes2
answers544
viewsA: dot width index 100%
If you don’t have textures or background images, a very "cheap" way to do it is to make the entire line dotted, and "cover" with the background of the end elements (the name and number). The…
-
2
votes1
answer1235
viewsA: How to create an array dynamically in PHP?
I suggest learning the basics of the language before doing anything more complex. Here you test a condition within a loop, and she won’t change, so either she’ll add everything, or she won’t add…
-
6
votes3
answers3023
viewsA: Foreach Array incrementing another array
Probably what you want is this: array_combine( array $keys , array $values ); In your case: $array_aux = array_combine( $array['quantidade'], $array ['produto'] ); See working on IDEONE Handbook:…
-
6
votes1
answer51
viewsA: How to show string to a given occurrence?
The function strstr has the third parameter, which serves for this: strstr( $origem, $termo, $flag_somente_antes_do_termo ); Example of use: strstr( '123456789', '5', true ); Upshot: 1234 To apply…
-
6
votes2
answers298
viewsA: How to run audio with Pyqt?
If you want to use Pyqt’s native method, you have QSound: meusom = QSound("alerta.wav") meusom.play() http://doc.qt.io/qt-4.8/qsound.html There is a method that returns a value bool, for you to know…
-
3
votes1
answer415
viewsA: How do I set a Tray Icon (tray icon) in a Pyqt application?
The class QSystemTrayIcon serves this purpose. http://doc.qt.io/qt-4.8/qsystemtrayicon.html Assuming your application is qApp, here’s a small example: trayIcon = QtGui.QSystemTrayIcon(…
-
9
votes1
answer1734
viewsA: Code for calculating 2nd degree equation returns "Nan" as roots
You are not considering the negative discriminant (complex roots) in your code. When the value of the discriminant (delta) is negative (and this is common in a quadratic equation), the function…
-
6
votes4
answers11110
viewsA: How to group SQL results by month and year?
About GROUP BY If you want to use aggregation, that’s basically it, but I don’t believe that’s what you’re actually looking for, if you’re going to use all the lines for reporting: SELECT SUM(…
-
2
votes1
answer29
viewsA: make Rows link in php
Something along those lines: $query = "SELECT paginas, Nome FROM links_paginas_filmes"; $result = mysqli_query($link, $query); while($row = mysqli_fetch_row($result)) { echo '<a…
-
2
votes1
answer86
viewsA: Check words that appear in foreach
Let’s assume that the original text is in $texto and the listing of words in $palavras, just to simplify reading. A relatively simple algorithm is this: $aTexto = explode( ' ', $texto ); $aPalavras…
-
6
votes1
answer61
viewsA: Mysql function does not merge equals
There’s more than one way. One of them, fairly simple, is to use JOIN: SELECT o.email, i.vezes FROM automovel o LEFT JOIN ( SELECT COUNT(*) AS vezes, email FROM automovel GROUP BY email ) i ON…
-
4
votes2
answers105
viewsA: Check if the same value is in one of the two fields
Both to search if a field has multiple values and to search if a value is found in several different values you can use the IN. See two examples: SELECT ... WHERE id IN (1,5,6,9); -- retorna linhas…
-
1
votes1
answer466
viewsA: How to put PHP variable with lower and higher value (min and max)
If you want a random number: $var = rand( 10, 20 ); Handbook: int rand ( int $min , int $max ) If you want to apply to an existing value $var = max( min( $var, 20 ), 10 ); Handbook: mixed min (…
-
4
votes2
answers15532
viewsA: How to do an UPDATE using data from two different tables?
You need to unite the two by the common key of both: UPDATE tabela1 INNER JOIN tabela2 ON tabela1.id = tabela2.id SET tabela1.dado1 = tabela1.dado1 + tabela2.dado2; See working on SQL Fiddle.…
-
8
votes1
answer98
viewsA: How to put signals between <td>
Has many ways. If you are using CSS3, follow a very interesting version. You can set the signals in HTML itself via data-Attributes, and control the CSS view. Your HTML looks like this:…
-
7
votes2
answers321
viewsA: Does the Mysql Select command differentiate numbers that have zero on the left?
The problem, as mentioned by @bfavaretto in the comments, is that you are probably storing your numerical data as strings. In addition, if you are looking for exact values, the operator is the = and…
-
8
votes1
answer95
viewsA: Concatenate two sql
Since version 2.1, the function LIST() do what you want: SELECT DT_OBS, LIST(DESC_OBS) AS LISTA_OBS FROM registros GROUP BY DT_OBS The LIST() Firebird is similar to GROUP_CONCAT() Mysql, however,…
-
5
votes1
answer442
viewsA: Search in different tables knowing what the result came from
General use of UNION with condition: SELECT campo1, campo2 FROM tabela1 WHERE ... UNION SELECT campo1, campo2 FROM tabela2 WHERE ... UNION SELECT campo1, campo2 FROM tabela3 WHERE ... UNION SELECT…
-
7
votes3
answers894
viewsA: What is the difference between foreach uses in php?
There is no difference in terms of functioning, internally both will become the same when executed. Its raison d'être is merely an option, it seems, for better legibility in different contexts.…
-
4
votes2
answers65
viewsA: How to call a function that prints the name of the calling function?
It is not a universal or standardized solution, but some browsers accept: function imprimir(id, nomeFuncao, frase) { console.log( imprimir.caller ) } See working on CODEPEN. Note that it returns the…
-
4
votes1
answer127
viewsA: Error in javascript/html code
Corrected reference to field result that doesn’t exist; renamed parcel function, not to conflict with the form; tidy quotes from alert(). Follow the corrected code: <html> <head>…
-
4
votes1
answer9012
viewsA: Truncate decimal places arbitrarily with Postgresql
For this there is this function: trunc( valor, [ casas_decimais ] ) and that: round( valor, [ casas_decimais ] ) The difference between the two is that trunc does no rounding, returning 40.16 as…
-
3
votes1
answer531
viewsA: Restrict access by htaccess
Answering the question, first of all, blocking for requests from outside via .htaccess is something like that: RewriteEngine on RewriteBase / RewriteCond %{HTTP_REFERER} !^http://www\.seusite\.com/…