facebook

Populating a Menu list from a LOCAL DATABASE

  1. MobiOne Archive
  2.  > 
  3. Getting Help – General
Viewing 15 posts - 1 through 15 (of 18 total)
  • Author
    Posts
  • #349708 Reply

    RogelioChavarria
    Participant

    Hi, i have hours trying to populate a list from a database table, my table has 19 colums and i need to know how to populate a menú from a data un a database column, next that the menú send to other page that shows all the information… please help me i have 3 months with the licence and im still cant do this.
    thanks.

    #349709 Reply

    Code_A
    Member

    Have you looked at the webSQL custom list example in the how-to section? Maybe it will be useful to you.

    #349718 Reply

    RogelioChavarria
    Participant

    Thanks, it works for me, so now i like to know how to add dynamic images?
    my db rows are for example: name, phone, picture (values: peter, 8112343434, peter.jpg)
    how can i add the file peter.jpg to the project and how i can called from mobione?
    thanks again!

    #349720 Reply

    Code_A
    Member

    Maybe this post will help: viewtopic.php?f=8&t=7099

    #349721 Reply

    RogelioChavarria
    Participant

    Thanks, ok, so i will add the pictures to the proyect as aditional files, but how can i load the pictures in the mobione design center?
    what kind of container i need to use?

    #349722 Reply

    RogelioChavarria
    Participant

    may be a html code… do you have something usefull?

    #349730 Reply

    Hi rogeliochavarria,

    If you are using as template the webSQL custom list example, these are the things that you will need to modify:

    1) Add an image widget to your item.mobi file
    2) Bind the data for your image attr adding it to every item that is used to represent your db. (list-db.js line ~108).

    var newItem = {
    ‘id’: results.rows.item(i).id,
    ‘image’ : results.rows.item(i).imageColName, <—
    ‘item’: results.rows.item(i).item};
    items.push(newItem);

    3) Make the image widget update with the image of the item requested when item.mobi screen is visited. Add next code to the updateItemScreen in the list-db.js

        $('[id$=image1]').attr("src",selectedItem.image);

    Note that image1 is the name of the image widget you added to item.mobi screen.

    Hope this is helpful.

    #349746 Reply

    RogelioChavarria
    Participant

    Thanks!!! It works, i have one more question, my database is over mysql and i have a cvs file, do you know if there is a tool to import-convert a cvs content file to the .js file?
    Thanks again.

    #349760 Reply

    Hi rogeliochavarria,

    I did a little research and found this library that might help you: jquery-csv 0.7 (Beta)

    Before you integrate it in a mobione app you should make sure that it works in your target platform(s) as this is a 3rd party component and your mileage may vary.

    #349794 Reply

    RogelioChavarria
    Participant

    Hi again, im almost done but now i need to use a combo box to filter the data from my local database, im usign “list-db-example”, im trying to use a combobox to filter the data by x or y… can you help me with this issue?
    in the list-db.mobi i need a custom list filtered by the selected values on the combobox, obviusly these values come from a column in my local database.
    example:
    DATABASE
    NAME, LASTNAME, PHONE, CITY

    COMBOBOX VALUES
    BEAVERTON
    HILLSBORO
    PORTLAND

    then the list will show only the data from the selected values on the combobox.
    Thanks again for your time and help.

    #349795 Reply

    Code_A
    Member

    This would be handled in your database SQL statement. Just pass the filter value when querying the database.

    For example,

    SELECT Name, LastName, Phone, City
    FROM Users
    WHERE City =  'Portland';

    Here is how you can get the selected value from the combobox, assuming its name is ‘cboCity’:

    var city = $('select[name="cboCity"]').val();

    If you need specific coding help within M1, then please post the code you are using to make the call to your DB for data.

    #349810 Reply

    RogelioChavarria
    Participant

    Ok, this is my list-db.js… the idea is that the combobox filters the data by “ESPECIE” and delete the checkbox
    Thanks for all your help. Octavio if you speak spanish will be better for me.

    Attachments:
    You must be logged in to view attached files.
    #349822 Reply

    Code_A
    Member

    Is your question related to javascript and coding of the m1 widgets (i.e., getting values from the combobox and dropdown), or is related to construction of the SQL statement to query the database (i.e., return only the filtered data)?

    #349828 Reply

    RogelioChavarria
    Participant

    Both, i need like to use the combobox to get values (java) and have only the filtered data in the list (SQL+JAVA). Can you halp me with this issue?
    at this moment i can use the statment WHERE in SQL to filter the data, but i dont know how to tell SQL from M1 what data i want. How comunícate combobox with sql and then sql with the list.
    Thanks!

    #349831 Reply

    Code_A
    Member

    Try adding a select function similar to the one below into your code.

    (NOTE: this code has not been tested…it is meant to be used as an example).

    This example assumes your combobox name is cboEspecie and that you are pulling all the fields of data from the “items” table.

    /**
     * Select from ITEMS table
     */
    function selectItems() {
        console.log('select: ' + $('select[name="cboEspecie"]').val(););
        db.transaction( function(tx) {
            tx.executeSql('SELECT * FROM items WHERE ID = ' + $('select[name="cboEspecie"]').val(););
            phoneui.back();
        });
    }

    If you need your results to match multiple selections, than you can concatenate your WHERE clause to include all selected items by just placing the ‘AND’ operator between the values.

    For example:

    ... WHERE Esepcie =  'Portland' AND 'Hillsboro';

    (You could setup a variable to hold the “WHERE” clause and then just add the variable to the end of the SQL statement).

    Here is how you can get a value from a combobox:

    $('select[name="combobox1"]').val()

    Here is how you can tell if a checkbox is checked:

    $('#form1-checkbox1 > input').is(':checked')

    Here is the MobiOne Widget Reference.
    Here is the W3 Schools SQL Tutorial

    Hope this helps get you started!

Viewing 15 posts - 1 through 15 (of 18 total)
Reply To: Populating a Menu list from a LOCAL DATABASE

You must be logged in to post in the forum log in