Modify Angular with my db and tables
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

I have 14 tables in my database and I need the database connection information and tables that angle be modified to the ones I have, as I can not disclose the names of tables, use TB_1 where you put the name of my table 1, TB_2 where you put the name of my table 2 and etc.

The EDIT appearing in precise lightbox that all tables are available for editing too. If you prefer to just put the file names and the lines to be changed along with the changes.

http://demos.angularcode.com/product-manager/#/

Let me know if I understood it: do you want to show your table's content to that client side?
feroldi almost 4 years ago
yeahp man!
scroll_lock almost 4 years ago
Did it work?
feroldi almost 4 years ago
awarded to feroldi

Crowdsource coding tasks.

1 Solution

Winning solution

Here's a demo I made: product manager.

Here's the download. There's already an sql for you to test.

Everything is already implemented, so I'll just show you how to use it:

In api/v1/config.php, you can configure your mysql database, putting the database name, table name, host etc.

Like this:

// You'll change the right-hand side.
define('DB_USERNAME', 'root');
define('DB_PASSWORD', 'password');
define('DB_HOST', 'localhost');
define('DB_NAME', 'angularcode_dbname');

In api/v1/dbHelper.php is located the functions you'll use to create, update, select and delete items from tables.

Here's an example:

$rows = $db->select("customers_php",array());
$rows = $db->select("customers_php",array('id'=>171));
$rows = $db->insert("customers_php",array('name' => 'Ipsita Sahoo', 'email'=>'ipi@angularcode.com'), array('name', 'email'));

$rows = $db->update("customers_php",array('name' => 'Ipsita Sahoo', 'email'=>'email'),array('id'=>'170'), array('name', 'email'));

$rows = $db->delete("customers_php", array('name' => 'Ipsita Sahoo', 'id'=>'227'));

And this is the described usage of them:

select(table name, where clause as associative array)
insert(table name, data as associative array, mandatory column names as array)
update(table name, column names as associative array, where clause as associative array, mandatory columns as array)
delete(table name, where clause as array)

UPDATE:

Using select, insert, update and delete functions

Note: I will use arbitrary columns and tables just for examples.

Whenever you select, insert, delete or update, you'll need to specify which table you're working on. If you want, for example, select a row from table Products with id 50, just do this:

$rows = $db->select('Products', array('id' => 50));

Where array('id' => 50) indicates what row corresponds to that id. You can use other columns there too, like name or email, whatever.

Now, to insert something, do this:

$db->insert('Products',
            array('name' => 'Ipsita Sahoo', 'email'=>'ipi@angularcode.com'),
            array('name', 'email'));

The first argument is the table you're working on. The second argument is an array containing a new row to be inserted. This row will have its own id. The key is the column and its value is the data to be inserted in that column. The third argument is an array holding the columns you're using. It's mandatory. Oh, yes, this function returns the new row as an result.

Updating a row is much the same as inserting one:

$db->update('Products',
             array('name' => 'Ipsita Sahoo', 'email'=>'new email'),
             array('id'=>'170'), // here you can use other columns too for searching
             array('name', 'email'));

First arguments is the table you're working on, as usual. Second argument is an array containing all the new data corresponding to its columns. Third argument is the row we'll update (id column identifies the rows). Fourth argument is an array holding the columns you're using. It's mandatory that this specific array contain all the columns you are updating.

Last one: deleting rows.

$db->delete('Products', array('name' => 'Ipsita Sahoo', id => 999));

First argument is the table you're working on. Second argument is an array for identifying a row similar to that.

Modifying files so that your columns apply everywhere

In api/v1/index.php

Look for the line that looks like this:

$rows = $db->select("products","id,sku,name,description,price,mrp,stock,image,packing,status",array());

This gets all columns from table products and returns them as a list of rows. You can change it to your columns. This way so:

$rows - $db->("products", "clienteid, clientmail, clienttelephone, typeproduct, descriptionproduct, amountpaid, amount_debt");

But I have changed it for you already, and better, I've let a place where you can change it easily. So in this file it looks like this:

$table = "products";
$columns = "clienteid, clientmail, clienttelephone, typeproduct, descriptionproduct, amountpaid, amount_debt";

Changing the table and columns content will change everything ONLY ON this file.

Here's the api/v1/index.php.

Sorry for the late.

So you can just search in all files from folders app/, partials/, for these columns names: id, name, price, stock, packing, description and status. Substitute them or add more. It's that simple.

Hi, isnt loading the products, and Im getting this error on /api/v1/products Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/api/v1/index.php on line 4 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/api/v1/index.php on line 4 Parse error: syntax error, unexpected T_STRING in /home/api/v1/index.php on line 4 Whats wrong?
scroll_lock almost 4 years ago
Can you upload the file /home/api/v1/index.php and show it to me?
feroldi almost 4 years ago
Sure! https://titanpad.com/N8oU4IxeQa
scroll_lock almost 4 years ago
Sure! https://titanpad.com/N8oU4IxeQa resolved, I changed the "\" by "/" now Im getting this error: Parse error: syntax error, unexpected T_FUNCTION in /api/v1/index.php on line 21 This is the line 21: $app->get('/products', function() { global $db; $rows = $db->select("products","id,sku,name,description,price,mrp,stock,image,packing,status",array()); echoResponse(200, $rows); });
scroll_lock almost 4 years ago
What's your PHP version? If it's under 5.3, you'll need to use 5.3 or newer. Because lambda functions weren't implemented until 5.3.
feroldi almost 4 years ago
ok , it worked! now show me if I want to change eg the "id " with " client_id " What are all the files you need to modify , since listing to edit , thank you
scroll_lock almost 4 years ago
ok , it worked! now show me if I want to change eg the "id " with " client_id " What are all the files you need to modify , since listing to edit , thank you thelostt, whats your mail? I have a project, want to know your price.
scroll_lock almost 4 years ago
See app/v1/index.php, on the get function call, there's this call: $db->select("products","id,sku,name,description,price,mrp,stock,image,packing,status",array()); . You can rename those. On folder partials, you'll need to rename the same names to those of your choice. On app/productsCtrl.js, there is a $scope.columns. The first list line is text:"ID",predicate:"id",sortable:true,dataType:"number". Just change the predicate option to the your new corresponding name. Another thing: do not change the id. It's used by SQL to identify the rows.
feroldi almost 4 years ago
Sorry I can't, show me step by step how to change the "name" for "email" in all files, thanks
scroll_lock almost 4 years ago
... Just tell me everything you want to change and I'll do it for you.
feroldi almost 4 years ago
Great! I have 14 tables in my database, I need to know the step by step to add the fields in my database that manager. Also I want to understand and modify if I ever need to . Now what I need is that the tables are added as follows. " clienteid " as the primary key . After "clientmail" "clienttelephone","typeproduct","descriptionproduct","amountpaid","amount_debt". with this information in the code I believe I can finish the customization. these data need to be listed and with the ability to edit
scroll_lock almost 4 years ago
I'll post it on the solution soon.
feroldi almost 4 years ago
Do all the tables have the same columns?
feroldi almost 4 years ago
I'm sorry, these data have spoken are the names of the columns, I have only one database.
scroll_lock almost 4 years ago
So the rows your 14 tables contain have the exactly same columns? Is that right?
feroldi almost 4 years ago
1 database, 1 table, 14 columns
scroll_lock almost 4 years ago
Ohhh, fine. I'm almost finishing then.
feroldi almost 4 years ago
thanks mate
scroll_lock almost 4 years ago
I need to know the data type of all columns, please?
feroldi almost 4 years ago