Posts by Wallace Maxters • 102,340 points
1,984 posts
-
2
votes1
answer379
viewsA: How to run a function only when printing the page?
Well, it looks like you can do it through the matchMedia. var mediaQueryList = window.matchMedia('print'); mediaQueryList.addListener(function(mql) { if (mql.matches) { // Meu script antes da…
-
2
votes2
answers1020
viewsA: Assign various elements different values using the same function
var addText = function(array, element){ $(element).each(function(i){ $(this).text(array[i]); }); }; $(function(){ var array = [ "meu primeiro texto", "Meu segundo Texto", "Meu terceiro texto", "E…
jqueryanswered Wallace Maxters 102,340 -
4
votes1
answer460
viewsA: How to enable and disable automatic scroll in a chat?
To make the automatic scroll change, you can do as follows: $(document).ready(function(){ var msg = $("#msg"); $("#send_msg").click(function(){ if(msg.val().length >= 1){…
-
4
votes1
answer158
viewsQ: Why does Facebook’s XHR request have that code?
I was analyzing the XHR requests from Facebook for study purposes and came across a code that I found curious to say the least. On the link similar to this 4-edge-chat.facebook.com/pull, has the…
-
1
votes3
answers8700
viewsA: Tag <a href> without changing the location bar
There is a way to leave a link using javascript. Example: <a href="javascript:void(0);">Seu Link</a> That way your page won’t "skip" when you click on it.…
-
4
votes2
answers2699
viewsQ: Revert a string and add method to native objects in Python
In Python, we have the method reversewithin the List. It reverses the order of a list. Example: [1, 2, 3].reverse() // [3, 2, 1] However this method is not present in a string. example (Python):…
-
1
votes1
answer1053
viewsA: How to change only a part within xml using php?
There are two classes in PHP that will allow you to do this operation. SimpleXMLElement and DomDocument I think, with the explanation of the PHP manual, there is no need to post examples. Basic…
-
2
votes2
answers408
viewsA: Long Polling with mysqli does not return data
The problem is in file_get_contents() of your code. When you use the file_get_contents() in a php file (the way it was used in your code), it will return to code string; ie, it will not be processed…
-
2
votes1
answer132
viewsA: Dropdown with "default" value and "all" option
In the controller, you check if the method is POST. When not, you set the value directly in the property datafrom the Cakephp controller. Behold: <?php if ($this->Request->is(array('post',…
-
4
votes2
answers1848
viewsQ: Is referencing the table itself in Mysql correct?
I am working on a system where the previous programmer structured a particular table of posts referencing itself (to be able to identify what would be the post comment) Sort of like this: Posts --…
-
2
votes5
answers10236
viewsA: echo or print, what really is the best option?
You better use the echo. Mainly because echo accepts multiple parameters; already the print nay. Which, in this case, would create a considerable difference in the time of printing the instruction…
phpanswered Wallace Maxters 102,340 -
6
votes2
answers350
viewsQ: What is the purpose of unset as cast in PHP?
As of PHP 5, there is a way to cast in order to convert a certain value to NULL. Example: $teste = 'teste'; var_dump((unset)$teste); // NULL $outroTeste = (unset) funcao(); var_dump($outroTeste); //…
-
4
votes1
answer1106
viewsQ: Subfolder problem and url rewriting with Laravel
I’m trying to do the Laravel 4 run in a subdirectory, using . htaccess to rewrite the url to the public folder Example: C:\xammp\htdocs\laravel4 The .htaccess is in rewriting…
-
4
votes1
answer674
viewsA: Percentage of ajax requests
I think you got the same code from the previous answer about "upload without refresh", where I had also answered. I didn’t add any event related to the press because it was a very simple example.…
-
5
votes2
answers1162
viewsA: Include creates space in Site Layout
This type of problem also happens because of the codification of documents. Try opening the files used with Notepad++ and convert to UTF-8 NO GOOD, choosing the option below Just click on the…
-
7
votes1
answer3152
viewsA: upload without refresh with Formdata, jquery
I use the jQuery, no plugin, so you can upload files. I will illustrate in a very simplified way: index php. <script src="jquery.js"></script> <script> $(function() {…
-
1
votes3
answers365
viewsA: How to use multiple $_GET in PHP through a URL
There is also a way to hide div by CSS when it is empty. Just use <style> #campo1:empty{ display:none; } </style> I would just like to draw attention to the care that should be taken…
-
4
votes1
answer97
viewsQ: In which part of the application is it more appropriate to reorder an array (database, server application, client code)?
Suppose, in a query to the MYSQL database, I need to take the last 1000 dice released, however, within these displayed results, his order must be growing (and not decreasing, as would happen in the…
-
5
votes2
answers378
viewsQ: How does PHP treat temporary expression regarding memory?
In PHP, it is possible to iterate the elements of a array through the foreach, both with the variable that contains it and with what PHP called "Temporary array Expression". Example: $myArray = ['a'…
-
4
votes2
answers3966
viewsA: How to send checkbox data to a mysql query?
If you plan to do some as a SELECT, you could use IN, based on the array obtained. You could do it like this: $parseInQuery = function(array $array){ return '`' . implode('`,`', $array) . '`'; }; //…
-
2
votes2
answers146
viewsA: How to fade() at different times in an img and id
As friend @Sergio said, you will have to hide the image first. Another way you can accomplish this procedure in steps is like this: <script> $(function(){ $('.imgRigth').fadeTo(0, 0);…
javascriptanswered Wallace Maxters 102,340 -
1
votes4
answers29756
viewsA: How to change dates from the American format y/m/d to d/m/y?
To convert dates from any format that date, you can use the native PHP Datetime class. Take an example: <?php $data = '2014/07/17'; $data_brasil = DateTime::createFromFormat('Y/m/d', $data);…
phpanswered Wallace Maxters 102,340 -
8
votes2
answers10723
viewsQ: Good practices when creating elements with jQuery
When I need to create elements in the DOM through jQuery, I usually use the following syntax: $('<div>').addClass('minha-div').attr({id: 'id-da-div'}); However, what I usually see in Internet…
jqueryasked Wallace Maxters 102,340 -
1
votes2
answers123
viewsA: Handle missing variables in array
Our friend @Cahe’s answer is a great solution. But I would like to share here another alternative that, perhaps, can make the code a little more simplified. Is the function Compact() According to…
-
19
votes4
answers955
viewsQ: How does Current function work?
For some time I always use the function current() in PHP, to get the first element of array (which is actually not its functionality, as it returns the current pointer on which the array is) and…
-
14
votes1
answer441
viewsQ: What is the purpose of Array and String Dereferencing implemented in PHP 5.5?
In the PHP manual, we can see New Features the functionality of Array and String literal Dereferencing. Example: echo 'string'[2]; // r echo ['stack', 'overflow'][1]; //overflow Thinking in case you…
-
1
votes4
answers868
viewsA: How to make Empty() accept the value 0?
From what I understand, you want to check if the value is empty with the empty, but wants to accept it if it is 0. in case it would have to be checked first if the value is equal to 0, since the…
phpanswered Wallace Maxters 102,340 -
4
votes2
answers366
viewsQ: What happens to class name resolution in php 5.5?
PHP 5.5 implemented a new feature, which consists of getting the class name through the keyword class: Example: namespace testando; class Teste{} echo Teste::class; // testando\Teste; This works…
-
0
votes8
answers56968
viewsA: PHP echo Special character problem ("ç")
I will give only one opinion as a complement, since the companions answered wisely earlier. I always set the option default_charset of php.ini as utf-8. This avoids problems like having to set up…
-
0
votes3
answers931
viewsA: Login Cakephp 2.0 does not work
As for the problem of using other fields instead of cake patterns, I was able to solve this by configuring it directly in the Appcontroller beforeFilter: $this->Auth->authenticate = array(…
-
4
votes4
answers23723
viewsA: How not to write duplicate data to Mysql with PHP?
There is also a way to directly execute a query in MYSQL that will only insert the record if it does not exist. It is a Conditional Insert. Example: $query = "INSERT INTO usuarios(login, senha)…
-
6
votes1
answer1195
viewsQ: Why does ob_get_clean wipe memory without starting the buffer with ob_start()?
I was one day doing some tests, analyzing how functions influence memory usage, and, by chance, called the function ob_get_clean(). I noticed that the function call "decreased" the memory size used…
-
0
votes10
answers29077
viewsA: Scroll through an Array and check if any element is empty
In this case, it has already been mentioned earlier about the function Empty, that checks if the value is null, "", 0, array(). The function array_filter() remove any of these cited within the array…
-
5
votes4
answers3280
viewsA: Integer with 0 to the left is printed as another number
You can get the same result without converting your values array for string, if using the function sprintf to save the formatted value you want to get. In this case, the option '%o' of the function…