Click here to Skip to main content
15,886,873 members
Home / Discussions / Linux, Apache, MySQL, PHP
   

Linux, Apache, MySQL, PHP

 
GeneralRe: PHP Fatal error: Uncaught mysqli_sql_exception Pin
Richard MacCutchan10-Apr-23 21:19
mveRichard MacCutchan10-Apr-23 21:19 
GeneralRe: PHP Fatal error: Uncaught mysqli_sql_exception Pin
Aruna KN10-Apr-23 23:46
Aruna KN10-Apr-23 23:46 
GeneralRe: PHP Fatal error: Uncaught mysqli_sql_exception Pin
Aruna KN11-Apr-23 4:23
Aruna KN11-Apr-23 4:23 
GeneralRe: PHP Fatal error: Uncaught mysqli_sql_exception Pin
Richard MacCutchan11-Apr-23 4:54
mveRichard MacCutchan11-Apr-23 4:54 
GeneralRe: PHP Fatal error: Uncaught mysqli_sql_exception Pin
Aruna KN11-Apr-23 4:57
Aruna KN11-Apr-23 4:57 
QuestionHow To Find 'DOES NOT CONTAIN' or 'DOES CONTAIN' in Php ? Pin
Member 159745539-Apr-23 10:27
Member 159745539-Apr-23 10:27 
AnswerRe: How To Find 'DOES NOT CONTAIN' or 'DOES CONTAIN' in Php ? Pin
Richard MacCutchan9-Apr-23 22:20
mveRichard MacCutchan9-Apr-23 22:20 
QuestionHow To Order By Adding Columns Values In SQL? Pin
Member 159745539-Apr-23 10:25
Member 159745539-Apr-23 10:25 
<pre>Hiya,

I need to learn the SQL query that counts all the points from more than one column and orders the matching rows based on most points in descending order.

EXAMPLE 1:
I do a keyword search for "mobile phone tutorial apps". Note 4 words.
Sql should find all the rows that contain any of these 4 keywords.
That means, since I searched for 4 keywords, sql should even pull-up those rows that just have even 1 or 2 or 3 of these 4 keywords in them.

Say, my mysql table looks like this:

id | kw1 | kw1_point | kw2 | kw2_point | kw3 | kw3_point | kw4 | kw4_point
--------------------------------------------------------------------------
0 | mobile | 3 | phone | 3 | apps | 2 | tutorial | 2
--------------------------------------------------------------------------
1 | mobile | 1 | phone | 1 | apps | 3 | tutorial | 3
--------------------------------------------------------------------------
2 | tutorial | 3 | apps | 3 | mobile | 2 | phone | 3
-------------------------------------------------------------------------
3 | mobile | 5 | tutorial | 5 | apps | 5 | usa | 5

NOTE: All 4 keywords exists on the first 3 matching rows. However, only 3 words exist in the final matching row.
And the final matching row's keywords are not in the order of my keyword search.
Here in Q1, this should not matter. Sql should ignore in which order the keywords are in each column when comparing the order of my searched keywords. All it should do, is:

A). Find matching rows, regardless of how many of my searched keywords exist on each row;
B). Count the totals of each points, (count more than one column in this case), in each row; And
C) List the rows in the point's descending order.

As you can see, from my example, the following are the keyword points of each row after calculating ALL their keyword points (all point columns):

id 0 = 10 point
id 1 = 8 point
id 2 = 11 point
id 3 = 20 point

So, in this case, the SQL query should present rows in this descending order:
id 3 = 20
id 2 = 11 points
id 0 = 10 points
id 1 = 8 points
So, in this case, the SQL query should present rows in this descending order:

id | kw1 | kw1_point | kw2 | kw2_point | kw3 | kw3_point | kw4 | kw4_point
----------------------------------------------------------------------------------------------
3 | mobile | 5 | tutorial | 5 | apps | 5 | usa | 5
----------------------------------------------------------------------------------------------
2 | tutorial | 3 | apps | 3 | mobile | 2 | phone | 3
----------------------------------------------------------------------------------------------
0 | mobile | 3 | phone | 3 | apps | 2 | tutorial | 2
----------------------------------------------------------------------------------------------
1 | mobile | 1 | phone | 1 | apps | 3 | tutorial | 3
----------------------------------------------------------------------------------------------

Had there been only a single "keyword point" (kw1_point) to calculate, then I would have written the SQL like this using prepared statements:
````
$sql = "SELECT * from keywords WHERE kw1 = ? OR kw2 = ? OR kw3 = ? OR kw4 = ? order by kw1_point desc LIMIT 100";
````

kw stands for "keyword_1". So, it is a column.

"kw_1_point" is another column.



"kw_2" is another column.

"kw_2_point" is another column.



"kw_3" is another column.

"kw_3_point" is another column.



"kw_4" is another column.

"kw_4_point" is another column.

</pre>

-- modified 9-Apr-23 16:34pm.
AnswerRe: How To Order By Adding Columns Values In SQL? Pin
jschell10-Apr-23 5:57
jschell10-Apr-23 5:57 
GeneralRe: How To Order By Adding Columns Values In SQL? Pin
Member 1597455310-Apr-23 6:35
Member 1597455310-Apr-23 6:35 
GeneralRe: How To Order By Adding Columns Values In SQL? Pin
jschell11-Apr-23 4:36
jschell11-Apr-23 4:36 
QuestionOnly few Errors left before Upgrading to PHP 8.1 Pin
Aruna KN8-Apr-23 6:40
Aruna KN8-Apr-23 6:40 
QuestionPHP isset for an Array Pin
Aruna KN6-Apr-23 4:51
Aruna KN6-Apr-23 4:51 
AnswerRe: PHP isset for an Array Pin
Richard MacCutchan6-Apr-23 6:06
mveRichard MacCutchan6-Apr-23 6:06 
GeneralRe: PHP isset for an Array Pin
Aruna KN8-Apr-23 5:06
Aruna KN8-Apr-23 5:06 
GeneralRe: PHP isset for an Array Pin
Richard MacCutchan8-Apr-23 5:09
mveRichard MacCutchan8-Apr-23 5:09 
GeneralRe: PHP isset for an Array Pin
Aruna KN8-Apr-23 5:19
Aruna KN8-Apr-23 5:19 
GeneralRe: PHP isset for an Array Pin
Aruna KN8-Apr-23 5:25
Aruna KN8-Apr-23 5:25 
GeneralRe: PHP isset for an Array Pin
Richard MacCutchan8-Apr-23 5:33
mveRichard MacCutchan8-Apr-23 5:33 
GeneralRe: PHP isset for an Array Pin
Aruna KN8-Apr-23 5:55
Aruna KN8-Apr-23 5:55 
QuestionPHP Warning: Undefined variable $conn Pin
Aruna KN3-Apr-23 2:45
Aruna KN3-Apr-23 2:45 
AnswerRe: PHP Warning: Undefined variable $conn Pin
Richard MacCutchan3-Apr-23 2:50
mveRichard MacCutchan3-Apr-23 2:50 
GeneralRe: PHP Warning: Undefined variable $conn Pin
Aruna KN3-Apr-23 3:48
Aruna KN3-Apr-23 3:48 
QuestionPHP 8.1 Count issue Pin
Aruna KN30-Mar-23 0:06
Aruna KN30-Mar-23 0:06 
AnswerRe: PHP 8.1 Count issue Pin
Richard MacCutchan30-Mar-23 0:45
mveRichard MacCutchan30-Mar-23 0:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.