Posts by gmsantos • 17,221 points
395 posts
-
0
votes3
answers211
viewsA: How to go through the tuples for an ID and check their values?
Instead of getting everything that’s already been paid for, why not get everything that has nothing pending? SELECT * FROM tabela_parcelas WHERE id NOT IN (SELECT id FROM tabela_parcelas WHERE…
-
6
votes2
answers1419
views -
5
votes4
answers3553
viewsA: How to get the next element in a PHP foreach
php has an internal library called SPL (Standard PHP Library) It has several objects and interfaces that help solve common problems that we find. We have several Iterators to solve your problem, two…
-
1
votes2
answers682
viewsA: Merge results and cross with another table
Assuming you can normalize the table_agendamentos according to the comments, it is possible to get the result you want with a group_concat. Normalized schedule table: SELECT a.id_agendamento,…
-
1
votes1
answer227
viewsA: How to set HTML attribute with @Yield() in Laravel?
Assuming dashboard is the name of your route, you need to convert to a valid url before returning to the href. Try the following: @extends('../layouts.master') @section('voltar')…
-
14
votes2
answers5413
viewsA: Work with Session without cookies to prevent session theft
Is there any way in PHP to work with sessions without the need for cookie creation? Yes, it is possible to work without allocating your session id to a cookie. However, because HTTP is stateless…
-
1
votes1
answer1171
viewsA: Update in another row in the same table by Trigger
According to this response from Stackoverflow, This is not possible in Mysql. Excerpt from documentation: A stored Function or Trigger cannot Modify a table that is already being used (for Reading…
-
9
votes6
answers11785
viewsA: Is there an advantage to using filter_input instead of isset?
The advantage in using the filter_input is in the facility to apply filters to your string. The same result can be obtained with the function filter_var, implementing the constants of FILTER The…
-
6
votes2
answers299
viewsA: Get XML tag data
You can use the class SimpleXml php. Here is a simple example of how to use the class. <?php $xml =…
-
3
votes2
answers183
viewsA: How to insert a header to each N records?
Another way to do this without using a counting array is through array_chunk. It will segment your array to each N elements generating a second array. Just insert the header between them: <?php…
-
1
votes2
answers113
viewsA: Error adding COUNT in CONCAT
Fields in aggregate functions such as max,min,avg or count shall be excluded from the clause GROUP BY. Try the following: SELECT DISTINCT TB_PRODUTOS.ID_PRODUTO, CONVERT( GROUP_CONCAT( DISTINCT…
-
2
votes4
answers2051
viewsA: Leave last 12 records and delete the rest in PHP/Mysql
Use a subquery with the property Ids inside a NOT IN combined with a DELETE (assuming that your visited table has a primary key). DELETE FROM visitados WHERE id_visita NOT IN ( SELECT id_visita FROM…
-
2
votes3
answers3063
viewsA: Put site path in a PHP include
It is not possible to do the include or require of files outside the same site file structure in the default php configuration. Your website should have a directory structure similar to this if you…
-
4
votes2
answers3308
viewsQ: Project C in Visual Studio
I’m learning C in college and will have to program in C. I tested with Visual Studio 2013 and 2019 Community Edition I can create projects in C++, but I couldn’t find anything like a "Visual C". Is…
-
9
votes3
answers1909
viewsA: Error creating a Mysqli database via PHP on Wampserver
Well, hitting the eye I saw some problems in your query. No need to put the name of the bank in simple quotes. If the database already exists, it will return an error as expected. You need to give a…
-
1
votes1
answer1611
viewsA: How to organize a C++ project into folder structure in Visual Studio
Look for the following button in Solution Explorer (Show all files). It will notify your project structure, allowing you to create folders to organize your project.…
-
3
votes1
answer4598
viewsA: How to list a sample of all tables in a Mysql database?
With the following query you will get what you need: Select concat("SELECT * FROM ", table_name, " LIMIT 10;") FROM information_schema.tables WHERE table_schema = database() It will return all the…
-
3
votes4
answers2028
viewsA: Identifying common snippets in two PHP strings
I don’t think there is a native php function that does this. I found a solution on google that solves what you need. function longest_common_substring($words) { $words = array_map('strtolower',…
-
1
votes3
answers1142
viewsA: Adapt query to create VIEW that returns sum of count of two Subqueries
Two other alternatives would be: Use a Sum() out of view: SELECT Sum(total) FROM View_no_Mysql_que_nao_aceita_subquery Create a view to the view CREATE VIEW mysql_precisa_de_gambiarras AS SELECT…
-
1
votes2
answers1280
viewsA: Treating XML file with PHP
Pay attention when using XML. All your errors are related when trying to use elements the wrong way, without following the structure of your document. Note also that some data is element attributes.…
-
3
votes2
answers324
viewsA: Generic repository with SQL
It is not mandatory to use a layer only for database interaction. It goes a lot of the project you are developing. For example, if you’re building a simple application, an To-Do List or a project…
-
4
votes3
answers9405
viewsA: How to convert a Mysql connection to Mysqli?
The problem you are facing is probably with function mysql_query. She had a change in the method signature and we need to pass the link of DB as first parameter (documentation): mysqli_query (…
-
1
votes3
answers201
viewsA: Internet Explorer Mode Patterns
In some situations, browser compatibility mode may be enabled by default. I don’t know if it’s just the company I work with, but here the intranet sites are loaded in compatibility mode by default,…
internet-exploreranswered gmsantos 17,221 -
10
votes2
answers240
viewsA: Search returns equal data
The best option for your case is to build your query more intelligently: <?php $camposFormulario = array( 'noiva_nome', 'noivo_nome', 'noiva_pai', 'noiva_mae', 'noivo_pai', 'noivo_mae', 'data' );…
-
4
votes2
answers1096
viewsA: Interest rate formula
From PHP 5.6 we can use the operator to exponentiation. $r = (($dados['preco'] * (1 + $dados['txjuros']) ** $dados['parcelas']) * $dados['txjuros']) / ((1 + $dados['txjuros']) ** $dados['parcelas']…
-
17
votes2
answers37795
viewsA: What does PSR mean?
The PSR (in English PHP Standards Recommendation) are project specifications proposed by PHP-FIG (PHP Framework Interop Group), a group composed of representatives of expressive PHP projects. These…
-
8
votes1
answer18996
viewsQ: Change address bar url without refreshing page
I am developing an application where a form with a series of <select> send information to a chart loaded via AJAX. I would like these filters to reflect in the browser url, to make it easier…
-
5
votes1
answer2137
viewsA: How to optimize this query query with other sub-consultations?
TL;DR What can improve query performance: Removal of ORDER BY unnecessary; Use of indexed field on filters in the WHERE; Do not use functions in WHERE (year(), month()) for field comparisons.…
-
10
votes1
answer1633
viewsA: How can I get a date 60 months ago?
In your query, you should use DATEADD SELECT GETDATE() AS Hoje, DATEADD(M, -60, GETDATE()) AS [60MesesAtras] Since you did not provide more details on your question, this is as much as I can help…
sql-serveranswered gmsantos 17,221 -
4
votes1
answer1301
viewsA: Mysql Local Database and Online Server Connection
What you want is the resource of Federated tables mysql. This feature is available from Mysql 5. With it it is possible to interconnect two different Mysql databases as follows: Create the remote…
-
0
votes2
answers274
views -
1
votes4
answers2214
viewsA: SQL query return total of days in a month on two dates
I arrived at the expected result by checking whether the data_saida is in the same month of the date entered through a IF of LAST_DAY combined with a DATE_DIFF: SELECT *, last_day(data_entrada) as…
-
4
votes1
answer49
viewsA: PDO showing connection data if catch trigger inside Alert(result)
Check your user and database passwords. They may be wrong. $pdo = new PDO("mysql:host=localhost; dbname=meubanco", "meuuser", "minhasenha"); To ensure that connection information is not displayed,…
-
6
votes2
answers7523
viewsA: Get the most recent month’s records
Considering the most recent month/year within the table, it is possible to use a variable: SET @ultimaData := (SELECT publicacao FROM teste1 ORDER BY publicacao DESC LIMIT 1); SELECT titulo,…
-
9
votes2
answers274
views -
1
votes1
answer215
viewsA: Remote connection of SQL Server 2008 Express
According to the Technet: The SQL Server Browser listens to incoming requests from features of Microsoft SQL Server and provides information about the instances installed from SQL Server on the…
-
7
votes1
answer230
viewsA: What is the difference between pg_query and pg_execute?
The difference between the two is that the pg_execute supports Prepared statements and the pg_query can’t stand it. It’s interesting to work with Prepared statements as this protects your…
-
2
votes5
answers6853
viewsA: Convert Date field data to Mysql month
Change your table in the database with alter table ALTER TABLE `tabela` ADD COLUMN `mes` VARCHAR(12) NULL; Then of a update in this table, with its date: UPDATE `tabela` SET `mes` =…
-
7
votes1
answer2749
viewsA: Import Excel Data to SQL Server
You can use the SQL Server Import and Export Wizard (included in SQL Server ) to do this. With it, you can even create the target table, or use an existing table. Using the 32-bit version, choose…
-
2
votes3
answers151
viewsA: Doubt in select de sql
You can use too >=, <= and the operator AND, but you need to repeat the field searched. SELECT num FROM tabela WHERE 'data_pesquisa' => dt_inicial AND 'data_pesquisa' <= dt_final…
-
3
votes1
answer85
viewsA: Problem in Mysql query
The problem in your query is in COUNT() and in the AVG(). They are aggregated functions and should be used together with GROUP BY to produce the expected result. Your query should look something…
-
2
votes1
answer387
viewsA: Multi-line update SQL server 2008 + PHP
Can use a UPDATE with DATEADD. UPDATE tabela SET vencimento = DATEADD(d, 30, vencimento)…
-
9
votes5
answers7129
viewsA: Number of weeks in a month
Based on logic of this other answer made function for that calculation. The functions date() of PHP has a problem with the year 2038. The difference if compared to the other answer is that here I…
-
3
votes2
answers7980
viewsA: What’s that "Mr-only" Bootstrap Twitter thing for?
According to the bootstrap documentation, this class serves to hide sessions from your page except on screen readers. It is used for accessibility issues, in this case more specifically aimed at…
-
3
votes6
answers57963
viewsA: How to convert UTF-8 characters in PHP
In addition to everything that has already been answered, make sure your webserver is configured to use UTF-8 as encoding. In apache, add the following line to your settings file: AddDefaultCharset…
-
1
votes1
answer192
viewsA: Database Allocation
The master is the database where SQL Server stores its settings at the instance level, similar to mysql in Mysql. The bank tempdb, as its name suggests, it is created for the temporary storage of…
-
1
votes2
answers830
viewsA: problem with namespace when running project
Because it has two distinct files, php will not automatically recognize both classes. You need to use an autoload for one class to "run" the other. Folder structure: view |_ classes |_ View.php |_…
-
1
votes4
answers2318
viewsA: Table load of a different seat
The simplest way to do this is by using SQL Server Import and Export Wizard. You define the source (RUP) and destination (STG_RUP) and select the objects you want to migrate. It is a very simple…
sql-serveranswered gmsantos 17,221 -
2
votes2
answers161
viewsQ: Result of a function in an array
I would like to insert the current year into an array type property of a class. I tried to use the function date('Y') directly in the attribution of the property, however as it did not work.…
-
3
votes3
answers2562
viewsA: Sort SQL by 1,2,3 instead of 1,10,2,3
Part of the question you already answered: The field is nvarchar, so it sorts alphabetically character by character. To order the way you want it is necessary to first extract the numeric part and…