Posts by Andrei Coelho • 6,196 points
249 posts
-
1
votes1
answer48
viewsA: Failed to Replace ID with PHP Team Name
Instead of creating another foreach just to search the names of the teams, it’s easier to do this at the time you’re creating the array, using two php features. Who are the array_search to search a…
-
1
votes3
answers95
viewsA: More or less a Select in array
You can use the array_column to take all the values of an array of a specific key together with the array_search to find out if the searched value exists. And then insert into the new array: $array1…
-
1
votes1
answer160
viewsA: Doubt Compare Values Returned from JSON Webservice
The problem is you’re willing to use $val['visitante'] not available in the array $retorno_resultados. Also, you are using the 'boss' key which is also not available. Another mistake is in yours…
-
1
votes1
answer59
viewsA: Doubt how to separate returned items from a web service
Since you are using php right in javascript, it is easier to resolve. First you transform the variable $retorno array. Then you insert the values found within this variable. As shown in the code…
-
2
votes1
answer337
viewsA: IF condition with database
Your code has an inconsistency. Maybe more... But I will quote one that is very clear to me. In this select you select only the user field and then you want to try using the id. So this won’t work.…
-
0
votes1
answer159
viewsA: Traversing array and separating by commas
You can do it like this: // array recebido $array = array( array("id"=> 18, "name" => "Drama"), array("id"=> 10765, "name" => "Sci-Fi & Fantasy") ); // string de saída $string = "";…
-
3
votes2
answers295
viewsA: How to create a simple markdown with PHP?
After several tests I created a solution, which I believe will contemplate all cases of string identifying the correct and wrong ones. For this, I started from the following premise: Cases that are…
-
1
votes1
answer35
viewsA: Bug script does not deliver purchase points
The error says the key buy_know is not set to be accessed in any variable. More specifically in this variable: $auctionInfo['buy_know']). You probably wanted to type $auctionInfo['buy_now']) The…
phpanswered Andrei Coelho 6,196 -
1
votes1
answer122
viewsA: Mask or remove email, phone and urls from a PHP string
You are wanting to hide the contacts of "smart" users who want to make direct contact with the end customer without your service. However, this code proposal I’m going to show you is not fail-safe,…
phpanswered Andrei Coelho 6,196 -
1
votes1
answer963
viewsA: Draw with different percentages
The solution proposed by @bfavaretto in the comments works perfectly. Here’s another suggestion if you couldn’t solve it. I made a solution based on a range of numbers that each element can have.…
-
0
votes1
answer63
viewsA: php - check if the user with email X has 1 or 2 open sessions
There are several ways to do this. One option is to create a hashed value that is saved in the database for a later check. For example: After the user confirms the email and password you open a…
phpanswered Andrei Coelho 6,196 -
1
votes1
answer75
viewsA: Take value from right set with 'ambiguous' fields
You can create a ALIAS for that field you want to redeem. That is, an alternative name for the field. So: $escalacoes = 'SELECT e.id, e.id_user, e.id_jogador, e.preco, e.status, jr.id_jogador AS…
-
1
votes2
answers754
viewsA: How to insert multiple records with 1 Insert?
In addition to the links indicated in the comments. For your case, you can do so: $ids = "1,2,3,4"; $idsArray = explode(",", $ids); $query = "INSERT INTO documento (id, data) VALUES ";…
-
1
votes1
answer253
viewsA: foreach to insert multiple Rows
The problem is that in your foreach you are replacing the variable $sql and is not concatenating the values. Therefore, only one record will always be inserted. In this case, only the last one the…
-
0
votes1
answer70
viewsA: How can I insert data into two different tables?
Use the multi_query to do more than one query at the same time. So: function newUser($connect, $name, $reg, $address, $phone, $email, $pass){ $query = "insert into user(email, password)…
-
2
votes2
answers288
viewsA: Understanding about MVC
The layer Model is where all the "Business Model" of your application is located. This also includes methods of recording, altering and reading in the bank. The layer Controller is a bridge, the…
-
2
votes1
answer463
viewsA: Take part of a Curl URL
Look I did so and it worked, see: $conteudo = file_get_contents("https://www.uol.com.br/"); $regexLinks = "/[w]*[A-z0-9]{1,}[\.]{1}[A-z0-9]*[A-z\.0-9_\/-]*/"; preg_match_all($regexLinks, $conteudo,…
-
0
votes1
answer58
viewsA: JSON for PHP + MYSQL
I took a test var_dump(json_decode($json,true)); and he was returning NULL. This value can be returned for several reasons. In your case the reason was a syntax error JSON_ERROR_SYNTAX. To fix this,…
-
1
votes2
answers715
viewsA: Help me with a php foreach array
Your json can return NULL for several reasons: I will list them below: JSON_ERROR_DEPTH // A profundidade máxima da pilha foi excedida JSON_ERROR_STATE_MISMATCH // JSON inválido ou mal formado…
phpanswered Andrei Coelho 6,196 -
1
votes1
answer101
viewsA: Place page numbers in PHP paging with MYSQL
You need to create a loop within the <ul>. Behold: <ul class="pagination"> <li><a href="?pageno=1">First</a></li> <li class="<?php if($pageno <= 1){ echo…
-
2
votes3
answers243
viewsA: Search 3 unrelated Mysql tables
The problem is that you are not using LIKE to do your search. The right thing is: (SELECT * FROM tabela1 WHERE tabela1.NomeUsuarios LIKE 'Dav%') UNION (SELECT * FROM tabela2 WHERE…
mysqlanswered Andrei Coelho 6,196 -
0
votes1
answer521
viewsA: PHP error when connecting to Mysql database
Try using the server IP in your variable $host. public $host = "127.0.0.1.00"; // IP do servidor public $user = "********"; public $pass = "********"; public $db = "djbteste"; Another thing, enter…
-
1
votes3
answers687
viewsA: How to join values in common php array?
I would do so: $arrayFinal = array(); for($x = 0; $x < count($vetor); $x++){ $codigo = $vetor[$x]['codigo']; if(array_key_exists($codigo, $arrayFinal)){ $arrayFinal[$codigo]['valor'] +=…
-
2
votes1
answer967
viewsA: Notice: Undefined offset searching inside array com for
Do it: if (isset($result[$i]) && in_array($result[$i], $horarios)) { ?> So this error will stop appearing because the isset($result[$i]) checks if THERE is the variable with the index in…
-
1
votes1
answer37
viewsA: php define path using preg_match/preg_replace?
Do it like this: $string = "/var/www*/te'st/test.php"; $string = preg_replace( '/[^A-Za-z0-9\-\\.\/]/' , '' , $string ); echo $string; See it working on Ideone…
phpanswered Andrei Coelho 6,196 -
2
votes1
answer62
viewsA: How to take a JSON data in this case
With json_decode and file_get_contents you won’t be able to because it’s blocked. My solution: You can use a stream that will read the file and turn it into a string for use. See: // abro uma stream…
-
1
votes1
answer265
viewsA: Separate respective item from a JSON array
Just make it work: $getJson = file_get_contents('file.json'); $listMenuJson = json_decode($getJson, true); foreach ($listMenuJson as $valor) { $categorias_alt = explode(',',…
-
0
votes1
answer167
viewsA: Register incoming api data with php
Your problem is here: $sql = "INSERT INTO filme (TITULO', 'CARTAZ', 'SINOPSE', 'GENERO') values ($titulo, $cartaz, $sinopse, $genero)"; 1 - The field TITULO is spelled TITLE' with only one quote.…
-
1
votes1
answer260
viewsA: Get the repeated records from one column from another column
Friendly: SELECT localidade, tipo_doenca as doenca, COUNT(tipo_doenca) as quantidade FROM pessoasDoentes GROUP BY localidade, tipo_doenca See working on SQL Fiddle In php you just do this: $sql = "…
-
2
votes3
answers68
viewsA: Problem in select order
In addition to the other answers, to do increasingly (ASC) just put the beginning of the date that will pick us record and order by date. By date: SELECT data, uniques, pageviews FROM tb_visitas…
-
3
votes3
answers690
viewsA: Check whether html form numeric field has a maximum of 6 numbers with PHP
In addition to the other answers, which are correct. I believe you want to evaluate whether the field is filled up 6 numbers. I created two options: Option 1 You can use the is_numeric: It will…
-
4
votes1
answer93
viewsA: Transform into ul
There are several ways to do this. I created this example in a simpler way, but I could have created a recursive function, for example. I did more for the challenge. =) This is the file text.txt…
-
1
votes3
answers65
viewsA: Object for Array php
Try it like this: $x = 0; while ($obj = $stmt->fetch(PDO::FETCH_ASSOC)) { $stmt2 = $db->query('SELECT * FROM wines a, uva b WHERE a.id_tipo = '.$obj['idtipo'].' AND a.id_uva = b.id GROUP BY…
phpanswered Andrei Coelho 6,196 -
1
votes1
answer56
viewsA: I can’t get the domain name with php
Use $_SERVER['SERVER_NAME'] to redeem the domain. Your code: define('DOMAIN', (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : ''));
-
1
votes1
answer68
viewsA: Concatenate string in the middle of another using array loop
I believe that’s what you want: function createcard($array){ // coloquei esse valor pois ele não estava identificado no seu código $pipeid = 12334; // altere depois $queryObj = array(); $string =…
phpanswered Andrei Coelho 6,196 -
4
votes2
answers1128
viewsA: Find value within an array
I would do so: $valores = array ( 0 => array( 'cod_produto' => 107, 'valor' => 20 ), 1 => array ( 'cod_produto' => 109 , 'valor' => 375.8 ), 2 => array( 'cod_produto' => 112…
-
2
votes2
answers576
viewsA: what’s the difference in using #my_div or div#my_div
1 - I wonder if there is any difference in the time of styling a page using div#minha_div or #minha_div... The difference is that when you put an HTML tag in front of the id or class it will only be…
-
1
votes1
answer534
viewsA: Select Mysql with an array in a table
You can use the OR within the SELECT. Thus: SELECT * FROM usuarios WHERE atuacao_usuario = 1 OR atuacao_usuario = 2 ... To do this automatically. Your code will look like this: $array_atuacao =…
-
0
votes1
answer53
viewsA: When mysql_fecth_assoc, don’t you think, it kills the rest of the code, how do you make it return something?
As quoted by @Bacco you need to use a record count to do this. Try to do so: if (mysqli_num_rows($resultado) == 0) { //echo 'fala'; $query2 = "DELETE FROM viagens WHERE id = '$id'"; return…
-
3
votes1
answer1355
viewsA: List days of the week with month and year PHP
ERRORS IDENTIFIED IN YOUR CODE As shown by you in the desired result, with the input of the day 01/04/2018 you would like the dates presented of a total of 5 weeks (in April). But in your code you…
-
3
votes2
answers460
viewsA: Generate CSV with side-by-side results in PHP
To answer your question I had to create other tables that were not informed to get the nome_representante and the nome_cliente. And to do tests I created several records, see: I put as optional the…
-
2
votes2
answers637
viewsA: Redeem id passed by URL without using GET
I’m not very good at REGEX. If your url is like this: "www.site.com.br/algo/seila/tantofaz/{15}" You can do it: $string = $_SERVER["REQUEST_URI"]; // pega a url preg_match_all ('/\{\d*\}/', $string,…
-
1
votes2
answers60
viewsA: mysql_num_row with Inner Join
I would do so: SELECT nome_loja, uf, (SELECT COUNT(*) FROM leads WHERE loja_selecionada = nome_loja) AS 'total' FROM lojas ORDER BY total DESC Also of course. =) See working…
-
2
votes2
answers190
viewsQ: Check connection at every instant
The thing is, I’m creating an app that depends on the internet connection for most services. To make it more dynamic, I thought I’d do something similar to the Youtube app. In the youtube app it…
androidasked Andrei Coelho 6,196 -
4
votes2
answers181
viewsA: check if the day exists or not with the if
You were trying to do UPDATE within the IF which checks whether there is no ID. It will not update because the id does not exist. It is right that this code is in an ELSE of this IF. Like this:…
-
2
votes1
answer485
viewsA: Script captcha generator in PHP does not generate the image
Your code is correct, what is causing error is a very common problem in the function imagettftext(). The problem of attaching the font to the text on fontfile of function. According to the manual:…
-
5
votes5
answers223
viewsA: Sum of hours greater than 24 hours
Although the other answers are right, they are not adding up the seconds. So I decided to create an alternative. I made that response based on in this answer and in this answer $tempo_inicial=…
-
1
votes1
answer54
viewsA: Problems submitting multi-line forms
The problem is that you are assigning the key to the VALUE. There is no such key at this value. Your key would have to be assigned to the array $input. Behold: print_r($inputs["ID"]); // isso…
phpanswered Andrei Coelho 6,196 -
2
votes1
answer248
viewsA: How to add a button that runs an application with php?
There are several ways to run a program by php. However, if the server is not enabled, the whole program cannot be run. Option 1 - Using exec() With this command it will execute the program and…
phpanswered Andrei Coelho 6,196 -
1
votes1
answer1069
viewsA: How to set and access session after using session_name
If you only use the session_name() it will return the current session name. When you create a name for the session_name($name) it will overwrite the current session name and return the old name. So…
phpanswered Andrei Coelho 6,196