Posts by Pedro Sanção • 5,639 points
147 posts
-
5
votes2
answers433
viewsQ: get word in given coordinate (x,y)
I am formatting a document for printing and need to add a page break + header and footer at certain coordinates, if the coordinate is in the middle of the paragraph I need to divide it. I can…
javascriptasked Pedro Sanção 5,639 -
1
votes1
answer44
viewsA: Select records in order
It is possible to do using only the ORDER BY mysql SELECT * FROM `tb_produto` ORDER BY `status` DESC, LENGTH(`foto`) > 0 DESC; When using the function LENGTH() the values '' (empty) and NULL for…
-
3
votes4
answers15429
viewsA: addClass and removeClass with Jquery
I considered the following to answer the Ids were duplicated the classes were repeating, I put everything in one parent item, with only one class moved the links inside the div, because they were…
-
5
votes2
answers1433
viewsA: Switch colors in table with PHP
Can only be done with CSS using the selector :nth-child(). Remove formatting routines from your PHP code makes it easy to read and maintain tr:nth-child(even) { background-color: #fff; }…
-
1
votes1
answer558
viewsA: PHP - View Animated GIF
Only to view it is not necessary to use any library. Just send an HTTP header and read the image file with readfile(). <?php header('Content-Type: image/gif'); readfile('url.gif');…
-
1
votes4
answers1283
viewsA: Alert message error
Mixing open PHP tags inside string Javascript is not a good idea, because it makes it difficult to read code. I suggest simplifying it as follows: <?php // salvar os dados em variáveis $mensagem…
-
1
votes2
answers613
viewsA: Dynamically delete multiple lines with PDO?
in my PDO queries I always use named parameters then it is not possible to use the "joker" ?, use the following code snippet $ids = array(); // sua variável $sql = 'SELECT ...'; $parameters =…
-
21
votes3
answers13303
viewsA: Star voting with radio input, javascript/css
It is possible to do using only CSS, with the brother selector ~ and some modifications to HTML. .estrelas input[type=radio] { display: none; } .estrelas label i.fa:before { content:'\f005'; color:…
-
6
votes1
answer5665
viewsA: Resize an image in a canvas element with js
I considered for the answer that the image should fill the whole space. The code shown checks only the ratio of the original image. I modified the code to check the aspect ratio of the image and the…
-
5
votes3
answers1746
viewsA: How to list a json object to generate a txt file and download that file via ajax request?
1 - how to read the object The object sent by Ajax will be available in $_POST as a multi-dimensional array 2 - how to iterate the object is received Whereas the following object dados that will be…
-
0
votes1
answer86
viewsA: Link being overwritten incorrectly when using preg_replace
You can use a lookbehind assertion to check whether the hashtag has a space before: /(?<=\s)#(\w+)/ The substitution does not change because the groups started with (? are not captured…
-
2
votes2
answers1445
viewsA: How to insert $_POST in HTML form input?
use the function filter_input() within the attribute value: <input type="text" name="username" placeholder="Username" value="<?php echo filter_input('username', INPUT_POST); ?>">…
-
2
votes1
answer1624
viewsA: Popular select based on a json date
in your fiddle has a part of javascript: $(document).ready(function(){ // linha 61 no fiddle $("#calendario").select(function(){ // seu código iniciado por $.ajax({ } } In this section is added the…
-
5
votes1
answer2239
viewsA: Load table with json using Datatables
When the data is nested inside other objects (multiple levels) notation should be used with . (dot) as documented. columns shall have the following value: [ {data: 'Contrato.id'}, {data:…
jsonanswered Pedro Sanção 5,639 -
3
votes1
answer159
viewsA: child element taking focus of parent element
This is the standard behavior, but with one condition you can avoid this behavior. var div = document.getElementsByTagName('div')[0]; div.classList.toggle('active'); div.addEventListener('blur',…
-
2
votes2
answers316
viewsA: Completing form with AJAX and Mysql
I added some parameters to your function, so the code part that will be repeated will be smaller. function consulta(url, resultId){ var xmlreq = CriaRequest(); var result =…
-
2
votes2
answers658
viewsA: Order consultation in the interim
It is possible to sort using a sub-query and variables: SELECT voz, produto, outra_coluna FROM ( SELECT voz, produto, outra_coluna , IFNULL(@orderA, @orderA := 0) , IFNULL(@orderB, @orderB := 0) ,…
-
1
votes1
answer767
viewsA: How to validate if there is an upload file?
Using the property files of <input/> file this check can be made: var input = document.querySelector('#file'); console.log(input.files.length); Example of use:…
-
1
votes3
answers906
viewsA: Create file with run permission
Cannot add execution privilege by default when creating files. The configuration umask (file-Creation mode Mask) system controls the default file and directory permissions. The default value is…
-
6
votes3
answers4536
viewsA: Incorrect accentuation when generating PDF
FPDF uses ISO-8859-1 or Windows-1252 encoding, and theoretically, as the collation Mysql is latin1_swedish_ci as strings do not need to be converted. If it doesn’t work without the conversion it is…
-
2
votes12
answers5446
viewsA: How to remove accent in upload with php?
Complementing the existing responses. There is a Unicode character block called Combining Diacritical Marks (combination diacritical signals), they are used to produce accents. If the text contains…
phpanswered Pedro Sanção 5,639 -
4
votes2
answers884
viewsA: How to call an original function in a php overloaded method
When there are more inheritance levels it may be necessary to use the class name instead of parent, the code snippet below exemplifies the uses for each case. <?php class Foo { public function…
-
1
votes4
answers444
viewsA: Mark contacts/hashtag in typing text with javascript
Whereas the search by user or hashtag should start when the cursor is over the keyword started with @ or # I made the code below, it will run a alert() when to start the search. // busca a palavra…
-
1
votes2
answers445
viewsA: Contact form does not validate and does not send some fields
The PHP code seems correct. Everything indicates that your form is sent by AJAX, because: there is a spinner at the bottom of the image the error message is generated by a echo followed by exit and…
-
1
votes1
answer123
viewsA: Get Querystring and redirect with . htaccess
the replacement is wrong in: RewriteRule ^conteudo.php(.*)$ http://meusite.com/nova-url-%1? [R=301,L] The %1? should be $1
-
1
votes2
answers53
viewsA: How to capture a certain part of a div’s content?
Following some suggestions of the comments I made the code below that iterates the child elements and compares the position in relation to the parent element. var div =…
javascriptanswered Pedro Sanção 5,639 -
2
votes1
answer257
viewsA: Displaying saved image in PHP database /Restaurant
You did not add the HTML tag <img/>. Change the line: echo " <td>". $res['img_prato'] ."</td>"; To: echo " <td><img src=\"" . CAMINHO_IMAGENS . $res['img_prato'] ."\"…
-
1
votes1
answer367
viewsA: REGEXP json search does not work properly when used string with parentheses
Your regular expression passes 11 as a group, so the regular expression captures the parentheses you must escape them with a backslash: $Search = sprintf('\'"%s":"([^"]*)%s([^"]*)"\'', 'telefone',…
-
3
votes2
answers1274
viewsA: Bootstrap News Slider
The class col-md-4 is only applied if the screen is at least 970px wide. To work on mobile devices add other classes according to screen size as per described in the documentation in: <div…
-
4
votes2
answers459
viewsA: What does "Auto Packing the Repository for Optimum performance" mean?
The auto Packing serves for GIT to recreate the internal indexes of the files (no commit or file is modified). It is an internal procedure that will expedite display of logs, tasks of push/pull,…
-
5
votes1
answer1423
viewsA: Deploy with GIT via FTP
There are several ways to do deploy using GIT. Although FTP is widely used it is not very safe and GIT does not support this protocol natively: Git can use four main protocols to transfer data:…
-
26
votes3
answers1203
viewsA: Why do parameterized SQL queries (name = ?) prevent SQL Injection?
It seems to me you’re referring to Prepared statements. What happens is that when informing a query with parameter for the connection library to the database, it treats the received value as a…
-
13
votes6
answers4694
viewsA: How to make a stopwatch continue counting after closing the page?
Considering that the stopwatch should store the current situation, I propose the following structure: When accessing timer.html, an AJAX request to get_timer.php takes the value of the stopwatch and…
-
2
votes2
answers56
viewsA: Add class to Regex result in preg_replace
It seems to me that you didn’t understand the function preg_replace, because you passed a regular expression as the second parameter, when you should use the text that should replace what was found.…
-
1
votes1
answer435
viewsA: Count SQL query with PHP percentage
You can iterate twice the query result. One to calculate the total and one to display the data. $result = array(); $total = 0; while ($row = mysql_fetch_assoc($query)) { $result[] = $row; $total +=…
-
3
votes1
answer661
viewsA: Replace text with HTML when it contains value in DIV
The best way is to iterate all target elements and replace Smiles with the HTML element with the correct class. Apparently if you will use this code to format the text, then to keep your code more…
-
10
votes8
answers2700
viewsA: Is it good practice to mix Php and Html?
Whether or not it is a good practice depends very much on opinion. This is a practice used, for example, in Wordpress template files, which mix HTML and PHP. Moreover, by default PSR-1 proposed by…
-
1
votes4
answers1122
viewsA: Align 4 Divs in CSS table
I saw you encoded the elements div as self-closing (<div id="div1"/>), what is wrong, you should always include the opening and closing tags of this HTML element. In addition to this…
cssanswered Pedro Sanção 5,639 -
13
votes2
answers207
viewsA: Regular expression start, end
You should wear a subpater (group enclosed in parentheses) with alternation (character | or pipe) in accordance with described in the manual (untranslated). That way the regular expression stays…
-
3
votes2
answers1325
viewsA: Browse query records with PHP PDO
the method PDOStatement::fetch() takes the cursor orientation as the second parameter, with the value of one of the constants PDO::FETCH_ORI_*. These parameters are only valid if the cursor of…
-
9
votes2
answers3923
viewsA: Run parallel process in PHP
To run a parallel process, follow the steps below. You mentioned that the hosting is in Locaweb and the function exec is locked on their Windows servers. I’ve seen other companies block this…
-
2
votes2
answers680
viewsA: Submit button even when cancel
At no time does your code prevent the submission of the form, to do this you must call the method preventDefault() of the event passed as a parameter of the function created in .click() $("#<%=…
-
1
votes1
answer797
viewsA: Error printing echo php in div
The Try/catch structure you used leaves one of the variables $ok and $error undefined (generates the error "Notice: Undefined variable"). I suggest using only one variable $message for both cases,…
-
5
votes2
answers4157
viewsA: What are <head> meta tags and what are they for?
Meta tags are information about the page used mainly by search engines and browsers. <meta charset="UTF-8"> informs the browser which character encoding should be used. Tags with the attribute…
-
1
votes1
answer634
viewsA: Maximum Array Size Passed by POST
Your description indicates that you may be facing a restriction of the PHP Suhosin patch. There are two other directives that should be added/changed if this module is active: suhosin.post.max_vars…
-
2
votes1
answer52
viewsA: Lowest index for multiple elements
Assuming you want to get the item index with the class error of <ul> you must use this: $(this).parent().find('.error').index() To get the index of the first item with the class error in…
jqueryanswered Pedro Sanção 5,639 -
1
votes2
answers1801
viewsA: Avoid duplicate data by applying use log counter
First I suggest you create a unique key with fields that cannot be duplicated, so Mysql itself avoids duplicity. For example: UNIQUE INDEX `nome_da_chave` (`nome`, `email`, `cidade`) With this key…