$data["params"] usage

Questions$data["params"] usage
Stas asked 9 years ago

Hello,

Thank you four you job.
I have tried to find an answer on my question but didn't found.
I'm not experienced with PHP and not sure if this question is regarding PHP Grid.
Could you please assist me with the following:

For example I have
$data["params"]["ID"]
1
2
3

$data["params"]["Name"]
John
Sara
Jerry

$data["params"]["Title"]
Manager
Sales
Sales

It there a way how to get ID, Name, Title as ID, Name, Title not as value (1,2,3,4; John,Sara,Jerry; Manager,Sales,Sales etc) when I'm doing foreach with it?

function update_client($data)
{
foreach($data[params] as $d)
{
echo 'Something here to get ID as row name in $data["params"]["ID"]["Name"]["Title"]';
echo $d;
\'echo' is just example to simplify the code. There will be mysql insert queries.
}
}

I would like to get output like bellow:

ID
1
Name
John
Title
Manager

Thank you.

4 Answers
Abu Ghufran answered 9 years ago

If i understand your query correctly, you can explode the data with comma and run insert or update query inside loop.
e.g. http://pastebin.com/5N2kz072

If there is something different, please share screenshot/code.

Stas answered 9 years ago

Hi,

Thank you for helping, but seems like there is something different.
Code is below:

function update_client($data)
{
foreach($data[params] as $d)
{
$LogTable = "`activity_log`";
global $StringID;
global $user;
mysql_query("INSERT INTO $LogTable (`action`,`attribute_name`,`new_value`, `updated_by`) VALUES ('Update', '$data[params][COLUMN_NAME not its Value]','$d', '$user')");
}
}

What I would like to get in Mysql after insert:

Select * from `activity_log`

Action Attribute_Name new_value updated_by
Update ID 1 John Dow
Update Name John John Dow
Update Title Manager John Dow
Update ID 2 John Dow
Update Name John John Dow
Update Title Sales John Dow
Update ID 3 Sara Jones
Update Name Sara Sara Jones
Update Title Sales Sara Jones

Abu Ghufran answered 9 years ago

You can use foreach with key => value format like …
foreach($data[params] as $k=>$d) { } and use $k as field name.

…..

function update_client($data)
{
foreach($data[params] as $k=>$d)
{
$LogTable = "`activity_log`";
global $StringID;
global $user;
mysql_query("INSERT INTO $LogTable (`action`,`attribute_name`,`new_value`, `updated_by`) VALUES ('Update', '$k','$d', '$user')");
}
}

Stas answered 9 years ago

Great!

Thank you

Your Answer

3 + 1 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?