Posts by Roberto de Campos • 5,345 points
235 posts
-
0
votes1
answer35
viewsA: Select record that contains result equivalent to a variable
As our friend @Inkeliz mentioned, the ideal is to reformulate the database and create a table to associate the job with the user. But if you can’t do this rewrite, you can circumvent this problem as…
-
0
votes1
answer284
viewsA: BETWEEN with Inner Join does not work
Try to do with this query: SELECT * FROM usuarios INNER JOIN matriculas ON matriculas.idaluno = usuarios.id AND matriculas.data BETWEEN :dataini AND :datafim WHERE matriculas.idcurso = :idcurso…
-
1
votes2
answers502
viewsA: Add previous line in mysql
The MySQL already has a native option for this purpose, just inform that it should use the AUTO INCREMENTO when creating the table, as this option was not made can also be informed through a ALTER…
-
1
votes4
answers1882
viewsA: Count substrings within a string
I believe you have nothing native for this purpose, but you can use the following function: function CountInText(Find, Text: String): Integer; begin Result := 0; while (Pos(Find, Text) > 0) do…
delphianswered Roberto de Campos 5,345 -
0
votes4
answers1139
viewsA: How to get last login of each user using mysql?
To query below will return a row for each codigo different from a user: SELECT a.`codigo`, MAX(a.`data`) `data` FROM `adm_historico_acesso` a WHERE a.`usuario` = '' GROUP BY a.`codigo`; Just put the…
mysqlanswered Roberto de Campos 5,345 -
3
votes1
answer1054
viewsA: How to optimize this query in Mysql that is too slow?
Add a INDEX in your table. As the filter field is the action, your INDEX reference to the same field: ALTER TABLE mdl_logstore_standard_log ADD INDEX IAction (action); If you want to deepen the…
-
2
votes1
answer60
viewsA: Mysql Cross Query
To query below returns what you need: SELECT * FROM produtos WHERE (origem LIKE ? OR destino LIKE ?) AND (origem LIKE ? OR destino LIKE ?) The passing of the parameters would look like this:…
-
2
votes1
answer165
viewsA: jQuery - Function . prop()
When you need to use special characters in your seletor, it is necessary to use \\(two backslashes), so that the character is treated as text and not as a regular expression. Another error contained…
-
1
votes2
answers792
viewsA: login with Cpf or email in php
Before you check if the user has only typed numbers, remove the dots and dashes using the function str_replace as follows: $login = $_POST['email_cpf']; $login = str_replace('.', '', $login); $login…
-
2
votes1
answer3711
viewsA: Find difference between two tables
Making a INNER JOIN, you can return the value difference by comparing the titulo and the very valor in both tables. SELECT * FROM ARQUIVOS a INNER JOIN CONFERENCIAS b ON a.titulo = b.titulo AND…
-
1
votes1
answer737
viewsA: Implement a PHP and mysqli like button
You can simply change the update: function curtir($conexao, $curtida) { $query = "update curtida set curtidas = curtidas + 1"; return mysqli_query($conexao, $query); }…
-
3
votes1
answer688
viewsA: Find Delphi component by string
As @Tiago Rodrigues said, form that you’re looking for probably isn’t inside that other form. Within Application you have that same function FindComponent, can use it to find your form. tela :=…
delphianswered Roberto de Campos 5,345 -
1
votes1
answer28
viewsA: Adjust currency using PHP
Use the function str_replace: <? $valor_sem_ponto = str_replace(',', '.', str_replace('.', '', "1.524,33")); echo $valor_sem_ponto; ?> Upshot 1524.33…
phpanswered Roberto de Campos 5,345 -
0
votes1
answer88
viewsA: How to enter the active class depending on the page the user is in?
Puts a id in ul main menu and also puts a id in each item. When you call your function to print the menu passes the id that you want to activate on that page, for example I want you to activate the…
-
2
votes2
answers289
viewsA: Why doesn’t Return work?
The return does not print anything on the screen, just returns, the correct is to do this: class Program { static void Main() { Class1 classe = new Class1(); Console.WriteLine(classe.GetValue());…
-
0
votes3
answers29
viewsA: Check if the product id exists in the simulator id_product
Your sql_simulador Maybe you’re making the wrong comparison, try replacing it for: $sql_simulador = "SELECT * FROM simulador where id_produto ='".$row_produtos["id"]."' order by nome_simulador ";…
phpanswered Roberto de Campos 5,345 -
0
votes2
answers1114
viewsA: Validate field after typing
I managed to make it work by manipulating events keydown, keyup and focus. I just add the validation existingname in the Bootstrap Validator when the user type at least one letter and stay 1 second…
-
0
votes2
answers1114
viewsQ: Validate field after typing
I’m using the Bootstrap Validator, the validation of the form is working very well. However, I wanted the validation of the field nome is executed only when the user has finished typing. Validation…
-
0
votes1
answer73
viewsA: Relationship of records of a table with itself
For this you need to make a recursive function. Recursive function is one that can make a call to itself. Since you didn’t put your code, I’ll put an example in a very abstract way: function…
-
2
votes1
answer373
viewsA: Run 2 `SUM` on a `UPDATE`
One comma was missing ,, after the closing of the parentheses of the select country custo: UPDATE pedidos a SET custo = ( SELECT case when SUM((b.qtd - b.qtd_devolucao) * b.custo) is null then '0'…
mysqlanswered Roberto de Campos 5,345 -
1
votes1
answer41
viewsA: How to divide the results from the comic into different lines as in an online store
Is missing you close to div .is-inside, try this way: $sql_journeys = "SELECT * FROM country_page_journeys WHERE countryPage_id = ".$row_img['country_id']." ORDER BY journeys_id"; $result_journeys =…
-
-1
votes1
answer224
viewsA: Problems with UTF-8 resale Locaweb
Try to configure the PDO for UTF-8 in creating the connection: conn = new PDO( 'mysql:host='.$host.'; dbname='.$db, $user, $senha, array( PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8' ) );…
-
3
votes2
answers791
viewsA: Function to summarize string in php
function resumo($string, $chars) { if (strlen($string) > $chars) return substr($string, 0, $chars).'...'; else return $string; } echo resumo("abcde", 4); Exit abcd... You can also use the…
phpanswered Roberto de Campos 5,345 -
2
votes3
answers52
viewsA: Multiple foreign keys in a single query
Make the call using INNER JOIN: SELECT a.nome_carta, b.nome_edicao, b.serial, c.tipo, a.efeito_desc, a.atk, a.def, a.link_img, d.atributo, a.id_lrl, a.quantidade FROM cartas a INNER JOIN edicoes b…
-
3
votes4
answers1346
viewsA: Select query by age group
You can do this using the IF, below an example: SELECT IF(idade <= 10, '0 - 10', IF(idade <= 20, '11 - 20', IF(idade <= 30, '21 - 30', IF(idade <= 40, '31 - 40', 0)))) faixa_etaria,…
-
0
votes1
answer176
viewsA: how to bring ten best media in mysql?
To list only the last 10 days, you can use the function DATE_ADD to subtract 10 days from the current date and compare with the date of your registration. Your query would look like this: SELECT…
-
-2
votes2
answers76
viewsA: How to instantiate $Pdo = connect() without repeating?
You can do it this way: require_once "conexao.php"; class User { public $nome; private $email; protected $senha; public function __construct(){ } public function insert($email, $senha){ $pdo =…
-
1
votes1
answer209
viewsA: Category modeling logic in an e-commerce
Categories with Sub-Categories, I usually make a single table. In this table I add a field idCategoriaPai. When making a category registration I leave this field null. When I register a…
-
2
votes2
answers1534
viewsA: Get value other than null javascript
Lacked some ; in your code. You also have a problem with your verification, if the value were null the verification document.getElementById("Anexo").value != "" would return true, and how you were…
javascriptanswered Roberto de Campos 5,345 -
0
votes1
answer336
viewsA: Catch up to 3 foreach position
Your problem is within the second loop, can do it this way: var quantidadeElementos = retorno.data.length; var i = 0; while (i <= quantidadeElementos) { if (i < 3) {…
-
0
votes1
answer1279
viewsQ: DIV Absolute respect padding DIV father
I need to put a div with the property position = absolute. However, the div father has a padding and the width: 100% of div son does not respect this padding. Would the only way out be to define the…
-
2
votes4
answers1877
viewsA: Export MYSQL information to JSON
To create the contents of a file JSON, first we create a array: $meus_dados = array(); After we have a array created we must popular this array: for ($i = 0; $i < 3; $i++) {…
-
0
votes1
answer35
viewsA: Select records under multiple conditions
Use the GROUP BY to group records by fields net, hora and AP: SELECT MIN(id) FROM tabela GROUP BY net, hora, AP
mysqlanswered Roberto de Campos 5,345 -
0
votes2
answers2295
viewsA: How to generate JSON files through forms?
You can do this with the javascript: var myJSON = JSON.stringify($("#id_do_meu_form").serializeArray()); The content will be in the variable myJSON, just use it any way you like.…
-
3
votes2
answers20
viewsA: Create COLUNM with results from an account made within a ROW - Mysql
If you want it in one SELECT, Bas make a query like this: SELECT Produto, Qtde, QtdeEntregue, ValorUnitario, ((Qtd - QtdEntregue) * ValorUnitário) ValorPendente FROM sua_tabela But if you want to…
mysqlanswered Roberto de Campos 5,345 -
1
votes2
answers234
viewsA: Base64 biometrics generating different codes for the same digital
Working with biometrics you can’t work for igualdade, the comparison should be made by aproximação, up because, one will rarely put one’s finger in the same position. Maybe, the recommended is you…
-
2
votes1
answer222
viewsA: Send id via POST in Jquery
Just inform the property data, follows below as would be in your case, replace seu_id for the amount you need. $(document).ready(function() { var dataTable = $('#employee-grid').DataTable( {…
-
1
votes1
answer104
viewsA: How to order a Mysql search with date in date format to get only the month
Just use the function MONTH of MySQL. SELECT MONTH(seu_campo);
mysqlanswered Roberto de Campos 5,345 -
0
votes1
answer134
viewsA: Create Trigger between tables
Apparently the error of sintaxe because it is missing to open a ( before the SELECT: CREATE TRIGGER tgr_log_insert AFTER INSERT ON tb_log FOR EACH ROW BEGIN IF( NEW.status = 'Desativado') THEN…
-
1
votes1
answer516
viewsA: JOIN between tables with some (s) of them empty
In tables that must be displayed even if there is no line corresponding to the clause ON, you replace the JOIN or INNER JOIN for LEFT JOIN. INNER JOIN or JOIN means that the row will only be shown…
-
0
votes1
answer503
viewsA: Perform condition on Trigger
NEW takes the new values and OLD takes the old values, follows below the example: DELIMITER $$ CREATE TRIGGER trg_anuencias AFTER UPDATE ON anuencias FOR EACH ROW BEGIN IF (NEW.status <>…
-
1
votes1
answer1222
viewsA: Query in two tables with Count
As you asked in the comments of your question, below is a query generic using INNER JOIN: SELECT a.id_contratado, a.Qtde_contratada, COUNT(b.id_contratado) qtde_servico, (a.Qtde_contratada -…
-
1
votes4
answers4554
viewsA: GROUP BY and ORDER BY Mysql
To bring all years of user without repeating, you can do so: SELECT DISTINCT ano, id, id_cliente, mes, status FROM programacao_clientes_mes WHERE id_cliente = 2 ORDER BY ano DESC…
-
2
votes1
answer25
viewsA: foreign key problems when selecting items
Tries to change his query for that reason: select t.*, d.nome_disciplina as id_discvinculada from textos t join disciplinas d on t.id_discvinculada = d.id…
-
2
votes1
answer22
viewsA: Specific cell change in Mysql
The mistake is in yours query, to perform an update does not need the word table, would look like this: $query = "update disciplinas set 'nome_disciplina' = '{$novoTituloDisciplina}' where id =…
-
1
votes2
answers26
viewsA: Error in the formation of the website title
Try this way: <title> <?php echo $nomeproduto.' - Vendas'; ?> </title>
-
2
votes3
answers882
viewsA: Insert multiple php mysql records
The correct thing is to have a table of images, and put a row for each image. In this table you have to have the id referencing the vehicle registration: Example: Table of Vehicles: CREATE TABLE…
-
1
votes1
answer100
viewsA: List 3 tables in a drug dispensation?
I accessed the link you left and apparently you managed to solve the problem, but anyway I will post a way to solve this because it can help other members. The first change I made was to group the…
-
1
votes1
answer35
viewsA: Query revision
Make sure it works this way: SELECT * FROM usuarios a INNER JOIN topicos_comentarios b ON a.usuario = b.autor WHERE a.banido = 'false' GROUP BY a.usuario ORDER BY count(a.usuario) DESC LIMIT 3…
-
0
votes4
answers634
viewsA: Find and delete different characters between strings
I didn’t understand why to do it, but anyway, it can be done like this: str1 = "carro" str2 = "carroa" str3 = "carrooao" if ((len(str1) < len(str2)) and (str2[:len(str1)] == str1)): str2 = str1;…