How to store array value in database using php?

Here we discuss about how to update the array value in the database.This concept is very helpful in PHP web application as it is used in many situations. You can store the user’s information in a single table. It is decreasing the new table creation for each user individually. You can manage all the user’s information in a single table and single query.

Let us discuss the sample code

Here the user update the studied information in the database


if(empty($_POST['col_name']))			//check the condition for array of data empty

{
echo "There's nothing in the array.....";
}
else
{
foreach($_POST['col_name'] as $key=>$name)	//Using foreach loop to retrieve and store the data
{
$query=mysql_query("update education set college_name='$name',
college_address='".$_POST['col_add'][$key]."',
course_study='".$_POST['col_study'][$key]."',
where employee_id=$employee_id);
}
}

In Real Time Example – QualityPoint Timesheet Live Demo

About

Smart Guy/ PHP Developer

Posted in MySQL, Php Tagged with: , , ,