Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

229
Views
Tengo datos de solicitud de 2 bases de datos. ¿Cómo puedo fusionar el código en una función?

Tengo datos de solicitud de 2 bases de datos. Pero necesito fusionar 2 solicitudes en una función y enviar datos a result.html

 function showResult(req, res){ var n = req.query.query mysql_conn.query('SELECT query_text FROM catalogsearch_query WHERE query_text LIKE "%' + n + '%" ORDER BY popularity DESC LIMIT 0 , 10', function(error, rows) { res.render('result.html',{result:n , related: rows.map(row => row.query_text)}) }) }

Necesita fusionarse con este código

 mysql_crawl.query('SELECT prod_name, full_price, discount_price, quantity, prod_link, images, prod_desc, status FROM `catalogsearch_fulltext` WHERE MATCH(data_index) AGAINST("cream") LIMIT 0 , 10', function(error, product_data){ res.render('result.html',{product_data: product_data})

¿Cómo puedo fusionar el código en una función?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Debido a que es asíncrono, tenemos que esperar hasta que tengamos ambas respuestas para ejecutar el render . (Si el módulo mysql admite promesas, puede hacerlo de otra manera ).

 var n = req.query.query; mysql_conn.query('SELECT query_text FROM catalogsearch_query WHERE query_text LIKE "%' + n + '%" ORDER BY popularity DESC LIMIT 0 , 10', function (error, rows) { // at this point, only the first query has been executed mysql_crawl.query('SELECT prod_name, full_price, discount_price, quantity, prod_link, images, prod_desc, status FROM `catalogsearch_fulltext` WHERE MATCH(data_index) AGAINST("cream") LIMIT 0 , 10', function(error, product_data) { // at this point, both queries should have been executed res.render('result.html', { result: n, related: rows.map(row => row.query_text), product_data: product_data }) }); });

Nunca usé este módulo, pero tenga cuidado con la inyección de SQL.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!