Link to home
Create AccountLog in
Avatar of Whing Dela Cruz
Whing Dela CruzFlag for Anguilla

asked on

How to create Web sql using var declaraion?

Hi, experts how to correct this code? I declare S1 = Mytable. when excecute the code below S1 would be the result. I want the result would be Mytable.

    function create()
    {
        var S1 = "MyTable";
        db.transaction(function (tx)
        {
            tx.executeSql('CREATE TABLE IF NOT EXISTS S1 (s_id INTEGER PRIMARY KEY ASC, id unique, firstName, familyName)');
        });
        alert("Successfully created!");
    }
SOLUTION
Avatar of PortletPaul
PortletPaul
Flag of Australia image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
ASKER CERTIFIED SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of Whing Dela Cruz

ASKER

Hi Paul Maxwell, the code above is already working on my pc. The only thing I need is that to replace "MyTable" into S1 since S1 was already declared as MyTable. There's no problem if make the code like this;
 
tx.executeSql('CREATE TABLE IF NOT EXISTS Mytable (s_id INTEGER PRIMARY KEY ASC, id unique, firstName, familyName)');

the thing I need is how to make the statement that would replace Mytable to S1 since S1 is variable. It is possible? thanks!
Hi chaau, your perfectly right! thanks both of you. God Bless!
Thanks Paul for reminding me!
no problem, it's all part of the service :)