Posts by Andrei Coelho • 6,196 points
249 posts
-
3
votes2
answers106
viewsA: Percentage of vote in php within a while
You can change your SELECT to do this automatically. See: SELECT id_candidato, nome_candidato, votos, votos * 100 / t.s AS `total` FROM candidatos CROSS JOIN (SELECT SUM(votos) AS s FROM candidatos)…
-
7
votes1
answer759
viewsA: PHP with DAO + mysqli
"DAO necessarily needs to be a class? Or I could create methods within a file. php without encapsulation of a class?" There is no DAO without classes. That doesn’t mean you can’t do something…
-
1
votes2
answers72
viewsA: How do I stream a file from my server?
With php you can use fopen $arquivo = "bots.txt"; fopen($arquivo, "r+"); // abre o arquivo para leitura e escrita $linhas = ""; while(!feof($arquivo)){ $linhas .= fgets($arquivo, 1024)."\n"; //…
-
2
votes1
answer153
viewsA: Calculation of interval duration
I did it this way: // cada servidor tem timezone diferente // para corrigir isso, basta adicionar a linha abaixo que ficará padrão // explicarei melhor no edit date_default_timezone_set('UTC');…
-
13
votes3
answers1038
viewsA: Turn m:s into seconds
An option would be using the explode: $tempo = "01:32"; $segundos = explode(":",$tempo); $total = ((int)$segundos[0] * 60) + (int)$segundos[1]; echo $total; Another option would be using strtotime…
phpanswered Andrei Coelho 6,196 -
2
votes2
answers39
viewsA: Insert only the filled line in php
Try to do so: ... código anterior ... $utente = $_POST['NomeUtente'][$i]; $quarto = $_POST['Quarto'][$i]; $data = $_POST['DataRegisto'][$i]; $miccao = isset($_POST['Miccao'][$i]) ?…
-
2
votes2
answers286
viewsA: Compare the combination of the numeric keyboard with the user’s bcrypt
If the final password is hashed crypt, YES! Because it is impossible to decrypt it to make an analysis of each character. Then you will have to encrypt all possible passwords and validate them. But…
-
2
votes1
answer257
viewsA: Run shell_exec with UTF-8 in PHP
You can use the setlocale to do this. This way: $locale = 'pt_BR.UTF-8'; setlocale(LC_ALL, $locale); // LC_ALL informa que tudo abaixo deste código será configurado para pt_BR.UTF-8…
-
7
votes3
answers331
viewsA: How to make this regex?
I did without REGEX because I find it easier. $text = "1ª Temporada - Nome da temporada 01 - Nome do ep um 02 - Nome do ep dois 03 - Nome do ep três 2ª Temporada - Nome da temporada 01 - Nome do ep…
-
0
votes1
answer586
viewsA: How not to let image appear in the drag?
This is a suggestion based on my knowledge. There are probably other ways to do. 1 - put the image as background and NOT with tag <img>. Thus: <style> .img { background-image:…
phpanswered Andrei Coelho 6,196 -
2
votes1
answer107
viewsA: return of array_search() considered false condition
If I understand correctly, just change the check: if( is_array($blogs) ){ if( ($index = array_search($url, $blogs)) !== false ){ $blogAtual = $blogs[$index]; } else { $msg = "<script> alert('O…
-
2
votes1
answer153
viewsA: Create PHP Infinite Menu
Try it this way: public function menuList($lists, $n = "") { if(!is_array($lists)){ $lists = $lists->toArray(); } for($x = 0; $x < count($lists); $x++){ $element = $lists[$x]; echo…
-
1
votes2
answers78
viewsA: Problem with Login
The problem is related to SQL. In my view there is an inconsistency in your query. It called me the attention you check in the table usuário if there is a record and registered in the table Cadastro…
-
2
votes1
answer66
viewsQ: Selection with LEFT JOIN
I’m studying sql and I don’t know if this is possible. But I have the following tables: Table contatos ______________________ id | nome | sobrenome | ______________________ That contains only one…
-
1
votes2
answers526
viewsA: Connect class database
You can create a connection class with static method. So the attribute $mysql will be configured only once and can be used by other classes. Class Conexao.php class Conexao{ public static $mysql;…
phpanswered Andrei Coelho 6,196 -
3
votes2
answers260
viewsA: variable to take certain numbers
The method split separates characters from a word when the delimiter is not informed. So: var variavel = "123456789"; var caractere = variavel.split(''); // aqui ele separa a string var variavel_A =…
javascriptanswered Andrei Coelho 6,196 -
2
votes1
answer48
viewsA: Question about PHP , where I can’t make an exclusion with one condition"
The error is that the connection to the database is missing: $consulta = mysqli_query($conexao, "SELECT * FROM usuario WHERE curso = '$curso'"); Your script will look like this: <?php include…
-
3
votes1
answer93
viewsA: When entering a record in Pag1, update the pag2
To do what you want, you need to create a Websocket connection. Websocket makes a connection between a client (from a web browser) to a server. Once a Websocket connection is established, it remains…
-
1
votes2
answers66
viewsA: Help with Multi Array
You can use the INNER JOIN to do SELECT. So: SELECT * FROM categoria INNER JOIN produtos WHERE categoria.id = produtos.id_categoria ORDER BY categoria.nome This way you will be able to select the…
-
3
votes2
answers319
viewsA: How to validate value entered in text field with php?
Simple: <?php if($_POST['CODNOME'] == "001"){ $msg = "mensagem1"; } else if(($_POST['CODNOME'] == "002"){ $msg = "mensagem2"; } else { $msg = "Opção inválida"; } echo $msg; ?> You can also use…
-
0
votes1
answer62
viewsQ: Create objects after external server response via API
Here’s the thing, I created a php API that generates a Json. THE LINK IS THIS for those who want to view. I was able to access the link and rescue the information, because I used a Toast to show…
-
1
votes1
answer1177
viewsA: Send and pick up GET by AMIGAVEL URL
You can do it like this: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^([0-9A-z_-]+)$ $1.php RewriteRule…
-
0
votes1
answer641
viewsQ: Perform an action after each character typed in an Edittext
The thing is, I’m having trouble finding out if the user typed something into EditorText. What I want is that, each character, number or letter that the user type, I can perform an action, soon…
androidasked Andrei Coelho 6,196 -
1
votes1
answer79
viewsA: Update SQL with Template Object
You can create the query string according to the values that are sent. For example: public function atualizar($aluno,$email) { $sql = new Sql(); $query = "UPDATE tb_alunos SET "; // string inicial…
phpanswered Andrei Coelho 6,196 -
1
votes1
answer968
viewsA: Limit links to be displayed in PHP and Bootstrap paging
You don’t need the for to do this, because you set the variables pagina_anterior and pagina_posterior. Replace this for: <?php for($i = 1; $i < $num_pagina + 1; $i++){ ?> <li><a…
-
2
votes2
answers2461
viewsQ: Delete repeats of values in Arraylist
I got the following ArrayList<Integer>: ArrayList<Integer> sequencia = new ArrayList<>(); sequencia.add(2); sequencia.add(11); sequencia.add(12); sequencia.add(13);…
-
1
votes1
answer347
viewsA: Which database connection is best?
There is no better or worse, in this case, because you use the mysql database. If you used another database, such as Postgresql, you would need to use the PDO. Because the PDO supports more banks,…
-
0
votes2
answers102
viewsA: I need a script (JQUERY) that goes to another page and saves the data.
Using the AJAX of JQUERY: First of all you need the linked JQUERY library in your script like this: <script src='jquery.js' type='text/javascript'></script> Imagine you have this form in…
-
2
votes1
answer283
viewsA: Session vs Database Query
There are problems of storing lots of data in sessions. One of them is the server performance. Each session you create in php has its content serialized and when it is done the conversion it…
-
1
votes2
answers179
viewsA: Ajax return a results loop
The problem is that the variable $linha_descricao does not exist, the right is $linha, because the results of your query are here: $linha = $resultado->fetch(PDO::FETCH_ASSOC);…
-
1
votes1
answer518
viewsA: Save user data to session after login
First you change your select: $sql = "SELECT id, name, email, telefone, endereco, numero, bairro, cidade FROM users WHERE email = :email AND telefone = :telefone "; Then you fill in: $user = $users[…
-
0
votes1
answer269
viewsA: Custom String Ordering
I created a script, based on yours, which will solve your problem. The code is commented. <?php $resultado = array("wtps", "tdtt", "tktf"); // aqui é o resultado do explode $posicoes = array();…
-
1
votes2
answers60
viewsA: Insert during a defined amount (PHP)
If you will insert records at once, sequentially, you can do so: $valor = array(); // aqui criamos o array com os valore escolhidos for($x = 1; $x <= $valor_escolhido; $x++){ $valor[] = $x ; //…
-
1
votes1
answer300
viewsA: Foreach group values
I created the code and in it I am explaining in detail: // primeira parte da string de inserção $sql3 = " INSERT INTO financeiro_sici_anatel_ipl3 (ano, mes, fistel,codmunicipio, IPL3_valor_F,…
-
0
votes1
answer64
viewsA: Error in the Database
The problem is that you are not selecting the database. The way you made the connection is object oriented, however its query is in procedural form. Change that line: $mysqli = new…
-
2
votes3
answers1645
viewsA: Search Database By Selecting Select Options
What you need to do is change two things... 1) Jquery: $(document).ready(function() { $("#estado").change(function(){ buscarOndeComprar(); }); $("#cidade").change(function(){ buscarOndeComprar();…
-
1
votes1
answer53
viewsA: Blank array - only removing half of them
This response is based on version 5.4 of PHP The problem is the language builder unset(). You don’t know exactly why, because PHP does not limit the use of this constructor in its manual, but this…
-
1
votes1
answer159
viewsA: PHP, marking checkbox for printing
The function membros_ver() does not return an array. The function returns a string. That is why you cannot use the foreach correctly. My suggestion: Use the mysqli_fetch_array. In the function you…
-
1
votes1
answer500
viewsA: Insert a query variable and display data in an already active Modal in PHP
To solve this, you can use the AJAX with jquery. I’ll show you an example below of how it works, but you’ll have to shape it as you need it because I don’t know how you want the content to be…
-
0
votes1
answer35
viewsA: PHP in conjunction with Mysql in user record
The mistake mysql_num_rows is because you are using mysqli. So the correct code is mysqli_num_rows. Also, for you to count the amount of record you need to use the variable of query thus: $veri =…
-
1
votes1
answer198
viewsA: Change PDF background according to database data (PHP, MYSQL, FPDF)
The problem is on this line $perfil_desconto = $resultado['desconto'];. You cannot identify because the variable $resultado is related to the query object. One option would be to add the…
-
1
votes2
answers79
viewsQ: Make selection from the results obtained from it
Good afternoon, I have the following table.. *eventos* ---------------------------------------- | id_evento | id_projeto | nome_evento | ---------------------------------------- I need to make a…
-
0
votes2
answers1733
viewsA: Problem with $_SESSION on login system, $_SESSION closes alone
"P.S. An important observation is that... this error happens only with the project that is hosted on the web, and in LOCALHOST works perfectly." The problem is in the file configuration PHP.ini…
-
2
votes2
answers369
viewsA: Traverse arrays with dates and compare with the current date
Simple as that... I commented on the code so you understand and can modify if you need. public function payments() { $date = date('Y-m-d'); // Retorna 2017-08-09 $services =…
-
0
votes1
answer139
viewsA: How to populate database tables with textbox data
The problem is that the variable $query does not exist. The variable you want to insert is the $sql, containing the query. Furthermore I believe that it is not necessary to put the query between…
-
1
votes1
answer346
viewsA: Return data from a class to index
Although you have already found the error. There is another way to do if you wanted to use one day: $stmt_count = $this->pdo->prepare($count); $stmt_count->execute(); $total =…
phpanswered Andrei Coelho 6,196 -
2
votes2
answers594
viewsA: problem when logging into form with php
"Not Safe" means your website has no security protocol SSL. You can get this protocol on some free and paid hosting sites, as suggested by @Inkeliz. But that’s not why you can’t log in. What happens…
-
0
votes2
answers374
viewsA: Create loop in templates with php
I don’t quite know how you want it to be printed at the end. But for you to use all variables in the array you should treat them separately from the code that makes the HTML change. An example: //…
-
3
votes1
answer1477
viewsA: Generate PHP system logs
I don’t know any framework, but it’s quite simple to do. I created the below example function using the fopen. In the function I put the files separated by date. In each line of the file has the…
-
1
votes1
answer1405
viewsA: How to fill in the inputs with the information returned from a query?
Just you use the foreach. It will sweep the array $dados and insert a input in each element. <?php require_once '../vendor/autoload.php'; use JansenFelipe\CnpjGratis\CnpjGratis;…
phpanswered Andrei Coelho 6,196