Posts by Roberto de Campos • 5,345 points
235 posts
-
1
votes2
answers2105
viewsA: How to save return in Ajax request in a variable
Ajax is an asynchronous function, so the program will not wait to run the ajax to then give the return of its variable category. But for our luck, we can do the function ajax synchronous by adding…
-
3
votes1
answer21
viewsA: Return date quantity in Mysql
Use the COUNT and the GROUP BY: SELECT `Data`, COUNT(`Data`) AS 'Quantidade' FROM sua_tabela GROUP BY `Data`;
mysqlanswered Roberto de Campos 5,345 -
1
votes1
answer33
viewsA: Read array from a field
In his explode has an extra space. Another problem is that every repetition of foreach you are printing the value of $arr when you should actually print the value of $v. Do it this way: $arr =…
-
2
votes1
answer80
viewsA: Logic of a Likes table
This is a matter of normalizing your database whenever you have the N:N it is necessary to create an auxiliary table. Create a table that contains the id of the postage and the id user’s: When any…
-
2
votes2
answers123
viewsA: Property with private set
Are not equivalent in that row: public int UmaPropriedade {get; private set;} The value of the property UmaPropriedade can only be changed by the class itself, nor can the child classes set this…
-
3
votes2
answers19092
viewsA: How to make INNER JOIN mysql
Thus: SELECT Veiculo.vei_nome, Veiculo.vei_cor, Marca.mar_nome FROM Veiculo INNER JOIN Marca ON Veiculo.mar_id = Marca.mar_id You could also create nicknames for your tables, avoiding excessive…
mysqlanswered Roberto de Campos 5,345 -
1
votes2
answers953
viewsA: SQL - Count number of records between rows
You can use the function GROUP BY along with a SUM and a IF. SELECT PessoaId, Semana, SUM(IF(Grupo = 1, 0, 1)) 'Tempo Fora' FROM Classificacao GROUP BY PessoaId, Semana In that query I assumed your…
-
1
votes2
answers99
viewsA: Update form not saved
Turns out there’s nothing being found in his WHERE, has to remove the extra spaces in the query: $sql = 'UPDATE pedidos SET ACERTO = "'. $acerto . '", SALDO = "'. $saldo . '" WHERE ID = "'. $id . '"…
-
1
votes1
answer69
viewsA: Crud making a mistake on the line where the foreach is?
The method query of PDO returns nothing see here, he just executes the query. What will return you the lines that came from the database in one array are the methods fetch, in the example below I…
-
-1
votes3
answers605
viewsA: Save a JSON file inside square brackets and separated by comma
You can do it this way: $dados = json_decode(file_get_contents ("dados.json")); array_push($dados, $_POST); $fp = fopen("dados.json", "a"); fwrite($fp, json_encode($dados)); fclose($fp);…
-
3
votes3
answers2980
viewsA: AJAX Return Handling with JQUERY
You can make the page return PHP in JSON: When it works out, you come back true: echo json_encode(array( "result" => true )); When not, you return false: echo json_encode(array( "result" =>…
-
0
votes1
answer53
viewsA: Syntax SQL query
All you have to do is make a LEFT JOIN: SELECT * FROM Categorias a LEFT JOIN Orcamentos b ON a.id = b.id_categoria ORDER BY a.id; If you want to list only one specific year of the budget, you can do…
-
-1
votes1
answer53
viewsA: Run user input on a given number
One option is to ask the user how many notes he wants to type, so just make one for on top of that amount: int notaTotal = 0; int qtdeNotas; int div; Console.WriteLine("Calculador de média…
c#answered Roberto de Campos 5,345 -
2
votes3
answers2456
viewsA: How to organize items from an array in alphabetical order?
You can do two for to sweep his array and put the if in the order of its criteria: <?php $linhas = array( "T3497012@CHOSTBRHDDSB@EICM_BORA@BPHS@Bamz", "T3497012@BHOSTBRHDDSB@EICM_BORA@BPHS@Bamz",…
-
0
votes1
answer209
viewsA: Insert data from one table into another by comparing ID
Your concept is wrong, you do not need to duplicate data in your database. For you to recover the name of the user who gave the gift is just to make a INNER JOIN, for example: SELECT a.id,…
-
7
votes1
answer102
viewsA: How does Python determine if a value is true?
This is because false is equal to 0 and true is equal to 1. Then it would be the same thing: a = [200,100] a[1] Output >>> 100 a = [200,100] a[0] Output >>> 200 In Python any value…
-
3
votes1
answer3183
viewsA: Require_once is unable to access file
The error occurs because the variable ABSPATH is being declared inside the archive config.php, so for you to use it inside other files it is necessary to load the file config.php before. Like your…
-
1
votes1
answer79
viewsA: Submit file with jquery
To upload an image without using input-file can do as follows: $("#am").on('change', function (e) { var reader = []; for (var i = 0; i < e.target.files.length; i++) { reader[i] = new…
-
2
votes1
answer84
viewsA: View day selection with php and Pdo
Change your select for: SELECT id, nome, membro, foto, data_nascimento, DAY(data_nascimento) AS dia_nascimento FROM membros WHERE DAY(data_nascimento) AND MONTH(data_nascimento) and at the time of…
-
1
votes1
answer39
viewsA: Value is not being taken via POST
The problem is that you are passing information without any reference. The property data of ajax gets a array of the kind key and value, that is, for each item it is necessary to have a key and a…
-
2
votes1
answer1012
viewsA: Remove spaces and accents with PHP
Use the function str_replace to take out the space before taking out the accents: $string="João é de Maranhão"; function tirarAcentos($string){ return…
phpanswered Roberto de Campos 5,345 -
1
votes1
answer223
viewsQ: Validate only numbers
I need to validate a string using Expressão Regular, it can only contain numbers. So I tried using the following expression /[0-9]/, but if the string contain a character and a number is considered…
-
0
votes1
answer43
viewsA: How to format the number in php by removing fractions
Use the function ceil: <?php $numero = 27.588877333333; echo ceil($numero); ?>…
phpanswered Roberto de Campos 5,345 -
2
votes1
answer210
viewsA: Display data in the same row
You can use the function GROUP_CONCAT together with the GROUP BY in the MySQL: <?php $sql = " select funcionarios.nome, group_concat(cargos.cargo) as cargo from funcionarios join cargos on…
-
0
votes1
answer45
viewsA: is_numeric is safe to select?
As it is only number, I believe it is not possible to make attack with SQL Injection, but to remove any doubt you can make this process using the bindValue(). Just use named parameters: $categories…
-
1
votes1
answer91
viewsA: Doubt with select case
How do you want to make one COUNT conditional, it is necessary to use the SUM and within it a CASE, if the condition is met will add 1 or add 0. select f.no_equipe, i.no_cbo, count(b.tp_atend), sum(…
-
0
votes2
answers63
viewsA: How do I move the company id from angular to php?
Add the variable idempresa in his formData: $scope.input = document.createElement("INPUT"); $scope.input.setAttribute("type", "file"); $scope.input.addEventListener('change', function(){…
-
0
votes1
answer300
viewsQ: Error making request via POST
I am sending information to a page on my server via GET through my application, until then it is working normally. However, now I need to send an image in the format base64, I believe that sending…
-
0
votes2
answers229
viewsA: Comparing a subquery with another subquery
To get this result it is necessary to make a INNER JOIN: SELECT A.`texto` FROM `A` INNER JOIN `B` ON SUBSTR(A.`texto`, 1, POSITION("=" IN A.`texto`) - 1) = SUBSTR(B.`texto`, 1, POSITION("=" IN…
-
1
votes1
answer32
viewsA: Query to count how many fields equal to 0 a record has
You can use the function SUM and compare each column if the column is equal to 0 you put 1, or you put 0: (SELECT id, SUM(IF(col2 = 0, 1, 0) + IF(col3 = 0, 1, 0) + IF(col4 = 0, 1, 0)) AS qtde FROM…
-
0
votes1
answer31
viewsA: Help - Logic Formulation - SQL, PHP, HTML
Using the GROUP_CONCAT, follows below as you can make your query: SELECT nome_equipe, id_equipe, GROUP_CONCAT(funcionario) funcionarios FROM quadro WHERE id_agencia=:id AND status=1 GROUP BY…
-
0
votes2
answers585
viewsA: Mysql search data Save to PHP variables
This is because you are overwriting the information. A simple variable cannot store separate information, to do this the variable has to be a array, that is, a list of variables. When you do:…
-
4
votes3
answers512
viewsA: Jquery monitoring key sequences
You can create a global variable to go concatenating and comparing, when it is equal you run and clean, when there is a character other than + you also clean, follows below an example:…
-
1
votes1
answer145
viewsA: Checkbox inside of While
<table border="2"> <tr> <th> Id </th> <th> Tipo </th> <th> Descrição </th> <th> NFe </th> <th>…
-
1
votes2
answers646
viewsA: Pick up Checkbox value from a form as Boolean for another form
Use the function Integer() to convert a Boolean for Integer, then multiplied by -1 why the return of this function when CheckBox1.Checked for True is -1 and not 1: var resInt: Integer; begin resInt…
delphianswered Roberto de Campos 5,345 -
2
votes3
answers465
viewsA: Column 'Activocirculation total' cannot be null
The message is saying that the column AtivoCirculanteTotal cannot be null, ie the field was created with NOT NULL. What is most likely occurring is that it is not being passed via POST the value of…
-
0
votes1
answer87
viewsA: How to display number of records by category in PHP and Mysql
That simple SELECT uses the GROUP BY categoria to group all records with the field content categoria equal. In the columns that we carry has its own categoria and COUNT(categoria) qtde which has the…
-
1
votes2
answers322
viewsA: Insert name instead of value option id
In his PHP you are recording the return of input in $codBairro and when you pass the parameters you send $codBairros, both must be equal: //Inserir no bando de dados $sqlBairro = "INSERT INTO…
-
5
votes2
answers663
viewsA: How can I differentiate a 'NULL' string from a null fact value?
The MySQL does not return a string with the content NULL when the field is null, it returns a column with no data, then you can check whether the return has given or not with the function is_null:…
-
5
votes1
answer113
viewsA: How to do multiple run with PDO
There’s nothing to do UPDATE, you can do only one. It will save running time because you will have fewer requests to the server: if (isset($_POST['ID'])){//Se informar o ID do usuário que deseja…
-
0
votes2
answers8319
viewsA: Is there a way to hide a url on a web page?
You can use the function file_get_contents, and in it pass the URL of your image. The function will return a base64 of your image, so you just put that base64 within the tag IMG, would look…
-
3
votes1
answer183
viewsA: Select with PDO and SQL barring HTML
Apparently missed you make the connection before using the function prepare, you can do it this way: $conn = new PDO('mysql:host=localhost;dbname=seu_banco_de_dados', 'seu_usuario', 'sua_senha');…
-
0
votes3
answers86
viewsA: find reference in another table
There are two ways to do this, the first is this one: SELECT * FROM lotes a WHERE a.id_cadastro NOT IN ( SELECT id_cadastro FROM cadastro ); and the second is this: SELECT * FROM lotes a LEFT JOIN…
mysqlanswered Roberto de Campos 5,345 -
1
votes1
answer58
viewsA: Can the entire variable receive a conditional value?
This variable will receive a value BOOLEANO, such an assignment would be the same as: if (iSinc or ACAO_PROX) then iSinc := True else iSinc := False; If you do the conversion, the answer will be…
delphianswered Roberto de Campos 5,345 -
4
votes1
answer85
viewsA: How to print the second value of an array?
Simple as that: echo $frutas["frutas"]["b"];
phpanswered Roberto de Campos 5,345 -
4
votes2
answers215
viewsA: Selection with various differences conditions (SQLSERVER)
You can use the IN, would look like this: SELECT * FROM table WHERE id NOT IN (15, 17, 23);
-
1
votes1
answer118
viewsA: Error inserting data into table!
First I took the liberty of altering its structure, like the field idaluno is AUTO INCREMENTO I think it’s best to work with the numeric type, so I switched to int: CREATE TABLE Aluno ( idaluno int…
-
1
votes1
answer453
viewsA: Return number of rows or columns of an array
For you to walk a Array Multi dimensional it is necessary to make two laços de repetição, follows an example: var Matriz: Array[0..1][0..2] of String; i, i1: Integer; begin //Laço de repetição para…
-
1
votes2
answers46
viewsA: Show member with id same column
The ideal is to reformulate the database and create a table to associate the position with the user. But if you can’t do this rewrite, you can circumvent this problem as follows: $id =…
-
4
votes3
answers1329
viewsA: Select data with Between in Varchar format
The correct is to store dates in fields of the type date, datetime or timestamp, but if you can’t restructure your table, with the function STR_TO_DATE you can convert string for date. In your case…