www.webdeveloper.com
Results 1 to 2 of 2

Thread: [RESOLVED] [WebSQL] How to use a variable value as ? in a SELECT ?

  1. #1
    Join Date
    Mar 2012
    Location
    France
    Posts
    23

    resolved [RESOLVED] [WebSQL] How to use a variable value as ? in a SELECT ?

    Hi,

    Let's explain myself.

    In my SQLite table, i have fields. Some of these are called j_weight1, j_weight2, j_weight3, j_weight4 and j_weight5
    I never need more than one of these "j_weightX" returned by a SELECT.

    Then I just create a variable ("weight"), and I give it as value the field "j_weightX" I need.
    Then, I ask the SELECT to return me the field "? as weight2", with the variable "weight" in the data brackets.
    Now, I think SELECT will put in a data "weight2" the value it found in the "j_weightX" field called.
    And... I'm wrong.

    In "weight2", select return me... the value of the variable "weight" : The NAME of the field. Not it's value.

    What am I doing wrong ?


    Code:
    var weight = "j_weight"+(tired+2);			
    tx.executeSql('SELECT s_name,s_screen_name,? as weight2,fighter.r_id FROM special,joinracespec,fighter WHERE joinracespec.s_id=special.s_id AND joinracespec.r_id=fighter.r_id AND f_id=? AND f_tiredness<=s_fatigue' , [weight,nbfighter], function (tx, data)
    {

  2. #2
    Join Date
    Mar 2012
    Location
    France
    Posts
    23
    Okay, it was hard, but i finally found : I just have to use concat :

    Code:
    weight = "j_weight"+(parseInt(tired)+1);
    tx.executeSql('SELECT s_name,s_screen_name,'+weight+' as weight2,fighter.r_id as r_id FROM special,joinracespec,fighter WHERE joinracespec.s_id=special.s_id AND joinracespec.r_id=fighter.r_id AND f_id=? AND f_tiredness<=s_fatigue' , [nbfighter], function (tx, data)											{
    And data.rows.item(i).weight2 just me the good result

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles