0

I am seeking help trying to add a new table in my third function called ingredients. I am not very familiar with javascript so I tried to duplicate code from newDosage which is similar to what I need to do. Unfortunately, right now all I see is 0, 1, or 2 and not the actual text from the ingredient table. If anyone can help me correctly call the table, it would be greatly appreciated. Thank you.

Below is my code. The first function pulls the database, the second function uses the results and the third function is where I have tried to add the ingredient table.

function listTreatmentDb(tx) {
    var category = getUrlVars().category;
    var mainsymptom = getUrlVars().mainsymptom;
    var addsymptom = getUrlVars().addsymptom;
    tx.executeSql('SELECT * FROM `Main Database` WHERE Category="' + category +
                  '" AND Main_Symptom="' + mainsymptom + '" AND Add_Symptom="' + addsymptom + '"',[],txSuccessListTreatment);
                  }

  function txSuccessListTreatment(tx,results) {
    var tubeDest = "#products";
    var len = results.rows.length;
    var treat;
    for (var i=0; i < len; i = i + 1) {
        treat = results.rows.item(i);
        $("#warning").append("<li class='treatment'>" + treat.Tips + "</li>");
        $("#warning-text").text(treat.Tips);
        $('#warning').listview('refresh');

        //console.log("Specialty Product #1: " + treat.Specialty1);
        if(treat.Specialty1){
            $("#products").append(formatProductDisplay('specialty1', treat.Specialty1, treat.PurposeSpecialty1, treat.DosageSpecialty1, '1'));
        }
        if(treat.Specialty2){
            $("#products").append(formatProductDisplay('specialty2', treat.Specialty2, treat.PurposeSpecialty2, treat.DosageSpecialty2, '0'));
        }
        }
}

 function formatProductDisplay(type, productName, productPurpose, productDosage, Ingredients, aster){
    var newDosage = productDosage.replace(/"\n"/g, "");
     if(aster=='1'){ productHTML += "*" }
    productHTML+= "</div>" +
    "</div>" +
    "<div class='productdose'><div class='label'>dosage:</div>" + newDosage + "</div>" + 
    "<div class='productdose'><div class='label'>ingredients:</div>" + Ingredients +
    "</div></li>"
    return productHTML;
}
3
  • Sorry for changing the topic but have you tried using PHP to handle the data layer (database) instead of JavaScript? Commented Apr 9, 2015 at 0:21
  • You're not querying the ingredients table, you're only querying the Main Database table. Commented Apr 9, 2015 at 0:23
  • Unfortunately I cannot use PHP since it's a web app. Barmar, can you tell me how to query the ingredients table? I thought everything is being pulled in the first function SELECT * FROM Main Database Commented Apr 9, 2015 at 0:24

1 Answer 1

2

You are missing an argument when you call formatProductDisplay(). You forgot to pass in treat.Ingredient.

Change:

$("#products").append(formatProductDisplay('specialty1', treat.Specialty1, treat.PurposeSpecialty1, treat.DosageSpecialty1, '1'));

To:

$("#products").append(formatProductDisplay('specialty1', treat.Specialty1, treat.PurposeSpecialty1, treat.DosageSpecialty1, treat.Ingredients, '1'));

Also do the same thing to the similar 'Specialty2' line right below it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.