Posts by rbz • 9,949 points
356 posts
-
9
votes1
answer18843
viewsA: How to sum all values of a column in Mysql?
How to do Summing up: SELECT SUM(PONTOS) AS total FROM tabela Adding up by users: SELECT NOME, SUM(PONTOS) AS total FROM tabela GROUP BY NOME Counting the amount of records per user: SELECT NOME,…
-
4
votes1
answer291
viewsA: How to query MYSQL in 2 columns and sort 1st results of title column and then Description column
You’ll have to do for subquery: SELECT * FROM ( (SELECT * FROM vagas WHERE titulo LIKE '%termo_de_busca%') UNION ALL (SELECT * FROM vagas WHERE observacoes LIKE '%termo_de_busca%') ) as apelido…
-
4
votes2
answers738
viewsA: PHP SQL Inner Join - Show name instead of ID number
I did not understand why so many parentheses. Since they are unnecessary, I took them. Solution: SELECT u.*, cat.nome as categoria, tip.nome as tipo FROM users u INNER JOIN categorias cat ON…
-
7
votes2
answers191
viewsQ: How to force justified size?
Example scenario I have a dynamically generated table (php), and one of the columns are vehicle boards. The problem is you get one a certain difference as the letters and numbers are "larger" and/or…
-
4
votes1
answer218
viewsQ: How does Git identify changing a file?
Example scenario I have the folder projetos on the server. On my local machine, where I have Git, I created a folder empresa, where I copied all the files from the folder projetos server. I did the…
-
4
votes1
answer4787
viewsQ: How do I create a project in Gitlab using git?
We can easily create a project on Gitlab and "sync it" by git: $ git clone [email protected]:user/teste.git But to do otherwise? Create folder and local project, and send as a "new" in the Gitlab?…
-
22
votes2
answers2203
viewsQ: What are the differences between the states of the git files (untracked, unmodified, modified, staged)?
I’d like to know what the characteristics and differences between the states of the archives during its life cycle in the git. States: untracked unmodified modified staged…
-
2
votes2
answers78
viewsA: Is going into loop
Error You’re having 1,2,3,4,5... why are you printing $i (index) and not the $var (value). Correcting # junta todos arrays em um array único ($var) array_push($var, $linha['data']); array_push($var,…
-
0
votes2
answers212
viewsA: mysqli_prepare() expects Exactly 2 Parameters, 1 Given
You are passing wrong parameter in 2 places. A way to correct: Add the connection as a parameter and use it in the function mysqli_prepare: public function cadastro ($nome, $login, $senha, $conn){…
-
14
votes3
answers2334
viewsQ: What are the differences between "soft, Mixed, hard" in git reset?
I would like to understand better what each type of reset in the git makes with the file(s) (s): Types: $ git reset --soft [commithash] $ git reset --mixed [commithash] $ git reset --hard…
-
1
votes2
answers5048
viewsA: Run . BAT in the background on Windows startup
In my case, I use a script firing it for period, and then run with another user: Run minimized or hidden PHP script by Task Scheduler You can do it the way I did, and use the "While logging on"…
-
0
votes1
answer611
viewsQ: How to do version control with Gitlab?
Setting I have a local folder (on my machine) with all folders and files various projects. For some indications, I chose the Gitlab because I need to keep private projects. Doubts There is a tool…
-
5
votes2
answers212
viewsQ: UPDATE is a DELETE followed by an INSERT?
On another issue (In Trigger we have INSERTED, DELETED, but the "UPDATED"?) this doubt arose as to the form of the database execution, due to the form that the Trigger access an altered record.…
-
6
votes3
answers3659
viewsQ: In Trigger we have INSERTED and DELETED. Why not "UPDATED"?
Example scenario: I have the table/fields: documentos id documento pessoa item qtd valor The system gives INSERT and then UPDATE on this table in a continuous sequence (which would not come to the…
-
12
votes2
answers138
viewsQ: Is it necessary to use semicolons at the end of a "single expression" in PHP?
Example scenario: Let’s assume I have a page that’s generated by includes, and it even has a loop: <? require_once 'classes/classe1.class.php'; ?> <html> <head> <? include_once…
-
4
votes2
answers1938
viewsA: How to Sub Select in SQL
Answering your question: What do you want is not subselect and yes JOIN. Example of JOIN whereas your sale table will always have 1 book for sale: SELECT * FROM VENDAS VD INNER JOIN LIVROS LV ON…
-
1
votes2
answers415
viewsQ: Trigger automatically blocks the table (LOCK TABLE)?
About TRIGGER in any table: To TRIGGER blocks (LOCK) the table until the end of its execution? If not, when should I block it out? How do I do that blockade?…
-
0
votes1
answer43
views -
2
votes2
answers34
viewsA: Adjust query sql according to available discipline
How to do You can use the clause OR: SELECT AVG(IFNULL(pqas.fraction, 0)) * 10 AS MediaPT, AVG(IFNULL(mqas.fraction, 0)) * 10 AS MediaMT, gg.finalgrade AS NotaGeral, u.firstname AS Aluno, u.username…
-
1
votes1
answer424
viewsA: Phpmailer with Locaweb - Not saving emails sent in my Locaweb account
There’s no way they can be saved, because this is function of mail manager whatever you’re using. With the Phpmailer, is not using any, only authenticating to send the email, so there is the copy.…
-
11
votes2
answers487
viewsQ: Can we create artificial intelligence in any language?
About Artificial Intelligence, would like to know superficially, thinking of starting the knowledge in this area: Can be created in any language? Basically, what would be the concept that a code is…
-
0
votes3
answers137
viewsQ: Text abbreviation <td> does not work
I would like to apply abbreviation in a <td>: <td> TextoTextoTextoTextoTextoTexto </td> Displaying only: TextoTexto... I tried to use style="text-overflow:ellipsis" but it didn’t…
-
1
votes3
answers1353
viewsQ: File link for viewing / downloading / printing
Setting I have a list of files dynamically generated, and would like to have 3 options: Open up: display in browser (if it is PDF, JPG, etc); Download: download directly; Print out: send straight to…
-
2
votes2
answers1251
viewsA: Foreign key for different tables (Mysql)
You have several mistakes: Needs a PK field in livro Is missing the size in razao text, Are you doing wrong references of foreign keys ("Foreign key"). Correcting 1 - I added another field to be…
-
2
votes1
answer258
viewsA: Random Records with Criteria
Working: SELECT tbNew.ID, tbNew.NOME, tbNew.SEXO FROM tbLista tbNew WHERE tbNew.ID IN ( (SELECT TOP 10 tbLista.ID FROM tbLista WHERE tbLista.SEXO = 'FEMININO' ORDER BY Rnd(Len(ID))) UNION ALL…
-
3
votes1
answer43
viewsA: How do to "explode" sometimes receive more values?
You will have to process the values, of course in conjunction with your database. An example: $REG = $valor[1]; $COD = $valor[2]; $UNID = $valor[3]; (isset($valor[4])) ? $QTD = $valor[4]: $QTD =…
-
1
votes1
answer97
viewsA: How to remove, insert, or change a single character in a field in Mysql?
It is already complicated to treat value with decimals, even more converting to STRING and change character. The ideal would be to use calculations, define formulas, and not a gambiarra. Therefore,…
-
2
votes2
answers55
viewsA: Why do I get different results for the same values sent to a PHP function?
In the method function Func_2() you just treat whole. In the method Func_1() you are making calculations with a value floating (float, double, real). A solution option is to round the decimals of…
-
0
votes1
answer326
viewsA: Phpmyadmin Error - error when selecting Auto Increment
As stated in the Isac error and comment, can only have one field auto-increment. You may have other primary and/or foreign keys, depending on your need. From the print, probably the field id of this…
-
1
votes4
answers1185
viewsA: Change only the day of registration
Complementing answers: From the SQL Server 2012, there is the function: DATETIMEFROMPARTS Syntax: DATETIMEFROMPARTS ( year, month, day, hour, minute, seconds, milliseconds ) Example: UPDATE tabela…
-
2
votes4
answers1185
viewsQ: Change only the day of registration
Scenario (example): I have the following table: ID | TIPO | DATAINCLUSAO 1 | 10 | 21/07/2018 09:34:51 2 | 10 | 11/07/2018 11:15:25 3 | 11 | 23/07/2018 01:52:31 4 | 11 | 04/07/2018 23:24:52 5 | 12 |…
-
4
votes4
answers2971
viewsQ: Identify how many days the month has (28, 29, 30, 31)
Is there any native function who identifies How many days is the month? Example: Step the value: 2018-08, then the return would be: 31. $dias = funcao('2018-08'); echo $dias; // resultado: 31 If not…
-
3
votes1
answer410
viewsA: connect in 2 banks with PDO
A basic example, on your question: function conectaBanco($nomeBD) { switch ($nomeBD) { # Servidor 1, Banco de dados 1 case 'BD1': $hostname='192.168.0.1'; $dbname='banco1'; $username='root';…
-
4
votes3
answers465
viewsQ: Join arrays by equal keys, but separating values
Scenario (example): I have 2 Arrays, X and Y (dynamically created, individual): $arX = Array('AAA' => 173.696, 'BBB' => 72.436, 'CCC' => 142.692); $arY = Array('AAA' => 127, 'DDD' =>…
-
4
votes2
answers222
viewsQ: Bold "<b>" does not apply in a range
In a table, if I apply bold (<b>) out of cells (<td>), it doesn’t work: <table> <tr> <b> <td>Cell A</td> <td>Cell B</td> <td>Cell…
-
13
votes1
answer363
viewsQ: Are there differences between /, /* */ and #?
Considering how important it is to comment on a code, I came up with this question. I realized there are several ways to comment lines/parts of code: // /* */ # Example: // comentando uma linha /*…
-
2
votes1
answer321
viewsQ: Field condition with subquery
Example of select: SELECT campo1, (ROUND(((t3.quantidade * t2.distancia * (SELECT TOP 1 valor FROM frete WHERE datainicio <= t1.dataemissao AND tipo = t4.tipo ORDER BY DATAINICIO DESC)) -…
-
4
votes1
answer2755
viewsQ: GROUP BY in query with column by subquery
I have the following select: SELECT A.CARRO, (SELECT TOP 1 VALOR FROM tab2 B WHERE B.DATA <= A.DATA ORDER BY B.DATA DESC) VALOR FROM tab1 A In (SELECT TOP 1 VALOR FROM tab2 B WHERE B.DATA <=…
-
1
votes2
answers149
viewsQ: Disable case sensitive only in a comparison
I wonder if there’s a way "disable" the case sensitive in a certain comparison. Example: var_dump('SQL'=='SQL'); # bool(true) var_dump('SQL'=='sQL'); # bool(false) I know there are ways to solve one…
-
0
votes2
answers585
viewsQ: Compare current record with previous record in loop/loop
Setting Let’s assume I have 100 records on any comic book. ID | PESSOA | CARRETO | ENDERECO | DISTANCIA 1 | A | C10 | XX | 20 2 | B | C20 | XY | 25 3 | D | C50 | XZ | 19 4 | D | C50 | XZ | 19 5 | F…
-
0
votes3
answers119
viewsA: targeting users validated by php
Direct to the page, and if any different value opens an error/access denied page: $nivel = $_SESSION['nivel_usuario']; if ($nivel == 1){ header("location: index1.php"); } else if($nivel == 2){…
-
2
votes1
answer39
viewsQ: Compare variable more than once, without repeating it
Example: Have a variable, that may be value between 1 and 10. I make the comparisons/conditions to print the result. $var = 5; if ($var == 1) echo 'A'; else if ($var == 2 || $var == 6) echo 'B';…
-
4
votes1
answer390
viewsQ: Object Serialization (serialize/unserialize)
I was looking at a topic about serialize in PHP. A very interesting function, but in view, very little used. About the function, I would like to know: An example of where would apply this function…
-
2
votes2
answers543
viewsQ: HTML Drag and Drop on mobile (touchscreen screens)
I’m thinking of making a panel using the features of Drag and Drop of HTML. Example taken from w3schools function allowDrop(ev) { ev.preventDefault(); } function drag(ev) {…
-
3
votes1
answer181
viewsQ: Display a GIF at start
Setting Have a page containing a div where content is loaded by Jquery and a div occult (hidden), with a GIF: <div id="lista"></div> <div id="loading" hidden> <img…
-
2
votes3
answers263
viewsQ: Do not display Warning de foreach
Example, I have 2 warnings: ksort($var); foreach($var as $v)...; Warning: ksort() expects Parameter 1 to be array, integer Given in C: www teste.php on line 15 Warning: Invalid argument supplied for…
-
1
votes1
answer95
viewsA: Logged in user can enter the login page
2 examples: Option 1 (will have to change its structure) You will give the include as logged or not: if(isset($_SESSION['status'])) { include_once 'painel.php'; } else { include_once 'login.php; }…
-
1
votes1
answer2592
viewsQ: Execute method/function when loading page
It’s not duplicate that: How to run a jquery script when loading a page I have a function that lists a content in div: function listar() { alert("listar"); // alert para saber se está sendo chamado…
-
2
votes1
answer402
viewsA: Inserting JSON object array in mysql with PHP
You can use the json_decode to convert JSON to Array. Example: $json = '[{ "id": 0, "codigo": "847010", "valorTotal": 3652.44, "qtdTotal": 20, "descricao": "Lorem ipsum dolor sit amet,", "produtos":…
-
1
votes2
answers861
viewsA: Connection to db SQLITE and SELECT * FROM reciclagem_data WHERE $variable
You are seeking the value of $_POST incorrectly here: $name = ["name"] An example of how to pull it: $name = filter_input(INPUT_POST, 'name'); Using the filter_input, also helps against SQL…