Running a loop for each mysql query result fields

shmnsw

queryResultArr is the array that olds mysql queries results, let say i have in my table two columns: doc_1_hits and doc_2_hits, but i don't know prior how much docs i have and i want to run a loop like you can see below: queryResultsArr[0].doc_i_hits instead of doc_1_hits.

i tried a: var str = 'doc_'+i+'_hits'; and then queryResultsArr[0].str but nothing..

for(var i = 1; i < 3; i++){
    if(queryResultsArr[0].doc_i_hits > 0 && queryResultsArr[1].doc_i_hits == 0){
        console.log(i);
    }
}
MrTippet

I think you could use the array notation and do it like below because they work similar in this case.

var a = 'doc_'+i+'_hits';
queryResultsArr[0][a] 

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

running a query and then running a query for each result of that query

From Dev

Mysql Loop By Query Result

From Dev

Loop array in mysql query and for the result

From Dev

PHP loop the INSERT MySQL for each result

From Dev

mysql query return first match of each result

From Dev

Mysql Query SUM adding each to eachother result?

From Dev

Running a Mysql query based on result of another mysql query?

From Dev

Running a mysql query on each value in a column in DASK

From Dev

mysql query result as a matrix table based on the 2 fields on different tables

From Dev

Loop the select query result set in MYSQL Stored Procedure

From Dev

Skip loop to populate form if result array from mysql query is empty

From Dev

Duplicate fields in col query result

From Dev

Running query inside loop

From Dev

Running query inside loop

From Dev

SQL - For Each loop in a query

From Dev

MySql query for duplicate fields

From Dev

Combine ActiveRecord::Result in .each loop

From Dev

Save the result of each cycle of the loop

From Dev

Mysql query to filter result

From Dev

running a for each loop for nested json

From Dev

MYSQL&PHP: running an INSERT INTO SELECT query within a PHP while loop, running slow

From Dev

PHP running MySQL query

From Dev

mySQL query is not running in MySQL Workbench

From Dev

Input fields running into each other/displaying awkwardly

From Dev

PHP/MYSQL: UPDATE query inside a for loop that runs the same query again instead of looping through each item?

From Dev

php / mysql to query one table with multiple identical fields and create one unique entry for each field in a second table

From Dev

Delete button for each mysql result

From Dev

Merge not-blank result fields by sql query

From Dev

Can I specify the result fields in elasticsearch query?

Related Related

  1. 1

    running a query and then running a query for each result of that query

  2. 2

    Mysql Loop By Query Result

  3. 3

    Loop array in mysql query and for the result

  4. 4

    PHP loop the INSERT MySQL for each result

  5. 5

    mysql query return first match of each result

  6. 6

    Mysql Query SUM adding each to eachother result?

  7. 7

    Running a Mysql query based on result of another mysql query?

  8. 8

    Running a mysql query on each value in a column in DASK

  9. 9

    mysql query result as a matrix table based on the 2 fields on different tables

  10. 10

    Loop the select query result set in MYSQL Stored Procedure

  11. 11

    Skip loop to populate form if result array from mysql query is empty

  12. 12

    Duplicate fields in col query result

  13. 13

    Running query inside loop

  14. 14

    Running query inside loop

  15. 15

    SQL - For Each loop in a query

  16. 16

    MySql query for duplicate fields

  17. 17

    Combine ActiveRecord::Result in .each loop

  18. 18

    Save the result of each cycle of the loop

  19. 19

    Mysql query to filter result

  20. 20

    running a for each loop for nested json

  21. 21

    MYSQL&PHP: running an INSERT INTO SELECT query within a PHP while loop, running slow

  22. 22

    PHP running MySQL query

  23. 23

    mySQL query is not running in MySQL Workbench

  24. 24

    Input fields running into each other/displaying awkwardly

  25. 25

    PHP/MYSQL: UPDATE query inside a for loop that runs the same query again instead of looping through each item?

  26. 26

    php / mysql to query one table with multiple identical fields and create one unique entry for each field in a second table

  27. 27

    Delete button for each mysql result

  28. 28

    Merge not-blank result fields by sql query

  29. 29

    Can I specify the result fields in elasticsearch query?

HotTag

Archive