node.js - mysql query in nodejs not returning the result as expected -
i have 3 tables, namely en_providers contain providerid, provideridsports , more fields, second table _lookup_sports contain sportid , sporttitle fields, table en_venue contain fields providerid,venuename,venudescription , more. relation between tables sportid _lookup_sports stored in serialized array format in provideridsports field in en_providers table. user enter sporttitle sportid selected usig following query.
con.query("select sportid _lookup_sports sporttitle=?",[req.body.sportname],function(err,data){ //something });
this query working fine , getting matched sportid. unserialize sportids stored in provideridsports, using phpunserialize module. below query working,
con.query("select providerid,provideridsports en_providers", function(err, data) { if (err) { console.log("length:" + err); } if (data.length) { ( var = 0; < data.length; i++) { console.log(phpunserialize(data[i].provideridsports)); } } });
and getting result as:
[ 31 ] [ 10, 78, 31 ] [ 10, 36, 64, 34 ] [ 16 ]
which unserialized sports ids provideridsports field. now, trying combine 2 queries , want providerid result when sportid first query 1 of value in array returned above. have written query as:
con.query("select providerid,provideridsports en_providers", function(err, info) { if (err) { console.log("error @ query 1" + err); } if (info.length) { (var = 0; < info.length; i++) { if ((info[i].providerid != 116) && (info[i].provideridsports != null)) { con.query("select providerid en_providers find_in_set((select sportid _lookup_sports sporttitle=? , sportactive='yes'),?)", [req.body.activity, phpunserialize(info[i].provideridsports)], function(error, data) { if (error) { console.log("error @ query2" + error); } else { console.log(data); } }); } } } });
i getting output as:
[ rowdatapacket { providerid: 1 }, rowdatapacket { providerid: 2 }, rowdatapacket { providerid: 3 }, rowdatapacket { providerid: 4 }, rowdatapacket { providerid: 5 }, rowdatapacket { providerid: 6 }, rowdatapacket { providerid: 7 }] [ rowdatapacket { providerid: 1 }, rowdatapacket { providerid: 2 }, rowdatapacket { providerid: 3 }, rowdatapacket { providerid: 4 }, rowdatapacket { providerid: 5 }, rowdatapacket { providerid: 6 }, rowdatapacket { providerid: 7 }]//it prining in loop [] [] error @ query2error: er_wrong_paramcount_to_native_fct: incorrect parameter count in call native function 'find_in_set' error @ query2error: er_wrong_paramcount_to_native_fct: incorrect parameter count in call native function 'find_in_set' //at last error repeating 3,4 times
i getting providerid en_provider table though doesn't match condition(that in continuous loop).i not able understand error why occurring when trying combine query. new write mysql query. appreciable. in advance.
Comments
Post a Comment