samedi 18 avril 2015

Node.js MySQL: Select-statement depending on query string?

I'm building an auction house. I'm using the nodejs-mysql package and I have this nodejs server.js-code for the main page, where multiple auctions are displayed:



// loop
var pollingLoop = function() {
// Doing the database query
var query = connection.query('SELECT a.`id`,a.`product_id`,a.`price`,a.`random`,a.`price_end`,TIMESTAMPDIFF(SECOND,NOW(),a.`date_end`) AS duration,p.`price_retail` FROM `auctions` AS a LEFT JOIN `products` AS p ON p.`id` = a.`product_id` WHERE TIMESTAMPDIFF(SECOND,NOW(),a.`date_end`) > "-1" ORDER BY `duration` DESC,`id` DESC'),
auctions = [];



  1. How can I accomplish that this query is changed when a $_GET['id'] is available to another SELECT-statement with a WHERE-condition? Because I want to add WHERE auction='$_GET['id']' for a single auction then (but server-side).

  2. Is there a way to make it more readable? Because when I press ENTER the SELECT-statement won't work at all. This is how it looks on the nodejs-server-file server.js: http://ift.tt/1ORW9NW


Aucun commentaire:

Enregistrer un commentaire