Posts by Hugo Borges • 5,294 points
332 posts
-
0
votes0
answers42
viewsQ: Load . SQL file and run with PDO
Well I am mounting a small code in PHP 8, PDO and Mysql 8. It will be responsible for creating a bunch of data and loading the tables from a file. SQL So far I’m doing it this way: // Tenho as…
-
0
votes2
answers81
viewsQ: LIMIT 1 with LEFT JOIN
Good to start I will post the SQL I rode here: SELECT a.*, b.name AS currentClubName, c.name AS transferorClubName, d.name AS contactName, d.phone AS contactPhone, d.phoneApp AS contactPhoneApp,…
-
0
votes0
answers48
viewsQ: Invalid key problem with JWT token and PHP8
Well I’m performing some tests of my project on PHP8 and I’m already refactoring it with some new features of PHP8. But I’m racking my brain with a library I use to work with JWT token. In this case…
-
1
votes1
answer66
viewsQ: While to Analyze Select Return
good afternoon! I’m having my first contact with Mysql, before I worked with Oracle, and I came across a problem that on Oracle, I had the following structure: for a in (select id, nome, salario…
-
0
votes1
answer41
viewsQ: Select in mysql grouping result by month
Well I have the following table structure: Categoria | DataOp | Tipo | ValorOp -------------------------------------------------- Carro | 2012-01-14 | 1 | 10 Moto | 2012-01-17 | 1 | 200 Venda |…
mysqlasked Hugo Borges 5,294 -
0
votes1
answer38
viewsQ: Assign values from a select to a variable
Well I am mounting a procedure in Mysql, and inside it I have the following code: DECLARE valorConta DECIMAL DEFAULT 0; DECLARE valorPGConta DECIMAL DEFAULT 0; SELECT Valor INTO valorConta FROM…
-
1
votes2
answers86
viewsQ: Consult the last 3 days in which there was record in the table
I have a table called OperacoesCaixa and in it I have the following fields: Cod, Valor, DataOp Well I need to make one select that I return the releases of the last 3 days, but I do not want to…
-
-2
votes1
answer64
viewsQ: Organizing an array based on a field
Well I am mounting an array with a query that comes from PDO it is giving me the result I want, but I do not know if this is the best way to do it. Follow my php code: // Array com os dados…
-
3
votes1
answer50
viewsQ: Difference between conventional SELECT and INNER JOIN
Model of the structure of the tables: Tabela: Bancos Cod Nome Tabela: OperacoesBanco Cod CodBanco ValorOp Historico Well I have these two models of SELECT: Example 1 SELECT b.Nome, o.ValorOp,…
-
3
votes1
answer77
viewsQ: Delete records in 2 tables with only 1 DELETE command
Model of the structure of the tables: Tabela: Produtos id_produto titulo_produto descricao_produto Tabela: Fotos id_foto descricao_foto id_produto We can observe that the tables have in common the…
-
0
votes1
answer78
viewsQ: How to predict next results from an array within the foreach
Well I have the following code: // Aqui eu recebos os produtos da API $produtos = array( array('cod' => 8, 'nome' => 'Produto teste 8', 'grupo' => 'Doces', 'valor' => 1007), array('cod'…
phpasked Hugo Borges 5,294 -
0
votes2
answers76
viewsQ: Select mysql of a ranking
Well I’m setting up a ranking of donations, the table in the database is like this: -- -- Estrutura da tabela `Doacoes` -- CREATE TABLE `Doacoes` ( `Cod` int(11) NOT NULL, `Doador` varchar(255)…
-
1
votes1
answer190
viewsQ: Use DISTINCT and SUM in the same Query
Good I have the following query: SELECT SUM(a.valor - a.desconto - a.credito + a.frete) FROM pedidos a, cadastro b WHERE a.status = '2' AND a.data >= '2019-03-29' AND a.data <= '2019-04-29'…
mysqlasked Hugo Borges 5,294 -
0
votes2
answers31
viewsQ: Select as a result of one day of the week
Well I have a select that returns the total order amount made in the current week. I do it as follows: SELECT SUM(valor) FROM pedidos WHERE YEARWEEK(data) = YEARWEEK(NOW()) Well I need a select for…
mysqlasked Hugo Borges 5,294 -
1
votes2
answers51
viewsQ: Capture value within the string
Well I have a variable that receives a string, with the name of the city and can happen to have the neighborhood within parentheses. I need you to separate that into two variables. Example 1:…
phpasked Hugo Borges 5,294 -
1
votes2
answers35
viewsQ: centering dynamically
Well I have the following code I’m putting together: .pg { width: 100%; } .pg>.produto { width: 250px; height: 300px; position: relative; float: left; margin: 10px; background: #ccc; border: 1px…
-
1
votes3
answers144
viewsQ: force ssl with htaccess and angular7
Well I have a website hosted at UOL, and I’m going through a strange problem. The structure of the site is so: | index.html | .htaccess | |app1 | | .htaccess | |index.html | |app2 | | .htaccess |…
-
0
votes1
answer2114
viewsA: php mysqli connection (Connection refused)
The error was in my mysql. I changed the file /etc/mysql/mysql.conf.d/mysqld.cnf. I changed the line bind-address = 127.0.0.1 for bind-address = 0.0.0.0 Then I restarted mysql and it worked.…
phpanswered Hugo Borges 5,294 -
1
votes1
answer2114
viewsQ: php mysqli connection (Connection refused)
Strange of nothing my php does not connect with my mysql, phpMyAdmin normally. Rodei a sudo /etc/init.d/mysql status and it’s all okay. My php is like this: $ip_bd_mysql_master = '127.0.0.1';…
phpasked Hugo Borges 5,294 -
2
votes0
answers73
viewsQ: Top command with php does not return the same terminal value
Well I am building a php code to monitor my CPU usage. I am using the top command that is native to linux. I am using a pc with Ubuntu server 18.04 for testing. Well what happens is that I open the…
-
1
votes1
answer72
viewsQ: recover cpu usage with php
Well I built the following code in php, to return me the CPU use. // Executa comando para consulta da CPU exec('top -d 0 -n 5 -b | grep Cpu', $cpu); // Monta array com os cores do processador…
phpasked Hugo Borges 5,294 -
0
votes1
answer95
viewsQ: Subfolder configuration in htaccess
Well I have a lodging with the following structure: index.html .htaccess app site Well, inside the app folder I have an application compiled in Angular 7.0 and inside the site folder I also have a…
-
0
votes2
answers66
viewsQ: Reading an array 2 times
Well I have the following array: $teste = array(1,2,3,4); When I want to write it on the screen I do so? foreach ($teste as $c) { echo $c; } The result is: 1234 I need to write the result twice and…
phpasked Hugo Borges 5,294 -
0
votes2
answers136
viewsQ: Prevent DIV from changing a defined size
I’m trying to put together an HTML page to print a label with 80mm x 40mm. It’s working, but when the person’s name is too big the label loses alignment, consuming 2 labels. I need to lock in the…
-
1
votes0
answers201
viewsQ: Generate barcode
I generate a barcode image as follows: http://localhost/Cod_Barras.php?codigo=342342341 (Ocorre o erro, a imagem fica em branco) Or http://localhost/Cod_Barras.php?codigo=34234234 (Gera a imagem…
phpasked Hugo Borges 5,294 -
1
votes1
answer66
viewsQ: calculating date in update mysql
Good need to update my accounts that are past due more than 5 months, I wanted to do this directly in mysql. The update is like this: UPDATE contas SET baixa_valivade = true WHERE data_vencimento…
-
0
votes1
answer480
viewsQ: convert html to excel
Well I’m doing the conversion that way: $html = " <table width='90%' border='1'> <tr style='background: #D7D7D7;'> <th>Título </th> <th>Título 2</th>…
phpasked Hugo Borges 5,294 -
-1
votes1
answer29
viewsQ: Check between time in a period
Well I’m trying to create a function that returns me true/false based on a certain time period. It buys the current server time and checks if it is within the reported period. Example: function…
phpasked Hugo Borges 5,294 -
3
votes1
answer49
viewsQ: retrieve date from bash Ubuntu
I am mounting a scrip to dump a Mysql server, the name of the generated file is like this (bckp_all_13-09-2018.tar.bz2), but I wanted to store the time too, so…
bashasked Hugo Borges 5,294 -
2
votes3
answers1758
viewsQ: Organize array in alphabetical order
Good when I want to organize an array in alphabetical order based on an array field I do so: // Compara se $a é maior que $b function cmp($a, $b) { return $a['nome'] > $b['nome']; } // Ordena…
-
-1
votes1
answer418
viewsQ: remove repeated data in mysql
I have the following table called cadastro: Cod | name | age With the data: COD NOME IDADE 2 | rafael | 15 3 | bruno | 17 4 | rafael | 33 5 | sabrina | 18 6 | bruno | 15 7 | paulo | 15 8 | rafael |…
mysqlasked Hugo Borges 5,294 -
3
votes2
answers1128
viewsQ: Find value within an array
I have the following array: array (size=80) 0 => array (size=2) ‘cod_produto' => int 107 'valor' => float 20 1 => array (size=2) ‘cod_produto' => int 109 'valor' => float 375.8 2…
-
4
votes2
answers897
viewsQ: Separate equal values in an array
Well I have the following array: $produtos2[] = array( "cod" => (int) 768, "nome" => "LOGITECH M535", "GRUPO" => "MOUSE" ); $produtos2[] = array( "cod" => (int) 2334, "nome" =>…
-
1
votes1
answer232
viewsQ: Configure log in crontab
Good use of crontab as follows. 0 * * * * wget -q -O /var/www/CronTab.txt https://www.meuseite.com.br/tarefa.php So it always creates a txt file 'Crontab.txt' with the result, and if you have any…
-
1
votes2
answers404
viewsQ: mysqli_fetch_array without using while
Good do a query in Mysql so: $usuario = $conexao->query("select * from cadastros"); I ride a json like this: // Monta array das tabelas while ($resultado_tabelas = mysqli_fetch_object($usuario))…
phpasked Hugo Borges 5,294 -
1
votes3
answers1676
viewsQ: Check if there is a field inside Json
Well I know how to recover a field inside a Json, I do so: $json = '{ "operacao": { "nome": "hugo" } }'; // Decodifica o Json $obj = json_decode($json); echo $obj->operacao->nome; But how can…
phpasked Hugo Borges 5,294 -
1
votes1
answer150
viewsQ: Comparison and calculation of time and date
Well I retrieve the date and time of a record like this: $sql = $conexao->query(select data, hora from pedido); $resultado = mysqli_fetch_object($sql); $resultado->data; $resultado->hora; I…
-
1
votes2
answers1169
viewsQ: Place border-bottom online table with css
With I have the following CSS that puts a border on all table rows. .tab_dados tr { height: 50px; border-bottom: 1px solid #D5D5D5; } Good has some way to make it be put the edge on all the lines…
-
3
votes1
answer305
viewsQ: effect with css Transition in Angular
Well I’m using a Progress-bar whenever I’m loading some data on the page. To stay cool I’m trying to put an effect for when she shows up and disappears. But the effect only works when it is hidden,…
-
2
votes2
answers217
viewsQ: Hide field from select mysql
Well I’m used to doing the select as follows: select nome, idade,cidade from cadastro This select me returns the fields name, age, city. But I want to do the opposite, I have a table with many…
mysqlasked Hugo Borges 5,294 -
2
votes2
answers48
viewsQ: Avoid error while recovering Json field
Good need to do an error handling while retrieving a field from a json. I have the following Json: { "Autenticacao": { "login": "123", "senha": "123" } } I’m retrieving the data like this: //…
phpasked Hugo Borges 5,294 -
0
votes1
answer226
viewsQ: How to check if json is an object
Well get a json on my page like this: // Decodifica o Json $obj = json_decode(file_get_contents('php://input')); echo $obj->Autenticacao[0]->login; The Json that is being sent is like this: {…
phpasked Hugo Borges 5,294 -
2
votes1
answer36
viewsQ: Get BD name on a mysql connection
Good make a connection to BD mysql like this: // Conecta-se ao banco do servidor ini_set('default_charset', 'UTF-8'); $mysqli = mysqli_connect('127.0.0.1', 'root', '123', 'teste'); Query($mysqli,…
phpasked Hugo Borges 5,294 -
0
votes2
answers266
viewsQ: Apply FILTER_SANITIZE or real_escape_string to all fields of a json
Good I have to apply one FILTER_SANITIZE_SPECIAL_CHARS on dodos the fields of a json. Currently receives json like this: // Recebo o json $json = filter_input(INPUT_POST, 'json', FILTER_DEFAULT); //…
phpasked Hugo Borges 5,294 -
1
votes1
answer206
viewsQ: How best to avoid sql inject
Well I have 2 ways to prevent sql inject, are they: first $input = $conexao->real_escape_string($input); 2nd $input = filter_var ($input, FILTER_SANITIZE_SPECIAL_CHARS); Query select * from…
-
0
votes2
answers1306
viewsQ: Check if there is a key in the/json array
Well I have the following json: { "Autenticacao": [{ "login": "teste", "token": "100", "senha": "123" }] } I get this Json like this: // Recebe JSON $json = filter_input(INPUT_POST, 'json',…
phpasked Hugo Borges 5,294 -
1
votes2
answers472
viewsQ: Reading data from a Json with php
Good I get the following JSON via post: string '{ "pedidos": [{ "feito_data": "2017-08-07", "valor": 40.0 }] }' (length=265) With php I handle the data like this: // Recebe dados do JSON $mix =…
phpasked Hugo Borges 5,294 -
0
votes2
answers811
viewsQ: Create barcode with imagecreate and html
I have a page that mounts a barcode, I want to know how to do to instead of the page return an html, it return an image. Example of how this my page: <?php $fino = 1; $largo = 3; $altura = 50;…
phpasked Hugo Borges 5,294 -
1
votes1
answer373
viewsQ: Run 2 `SUM` on a `UPDATE`
Well I’m trying to do the SUM of two different fields and give a UPDATE in another table. I’m doing like this: UPDATE pedidos a SET custo = ( SELECT case when SUM((b.qtd - b.qtd_devolucao) *…
mysqlasked Hugo Borges 5,294 -
4
votes3
answers1242
viewsQ: Update based on a select
I have to update the field custo table pedidos based on the field valor table produtos_pedidos. Whereas the a.id table pedidos must be equal to the field b.id_pedido table produtos_pedidos. I’m…
mysqlasked Hugo Borges 5,294