How many update records submit how to write SQL
First on the code:
Require ("inc/pdo.php");
$select = $dbc->prepare ("Select id,slide_name,slide_href,slide_img from Zt_slide");
$select->execute ();
while ($row = $select->fetch ()) {?>
Focus Chart Management
Submit to 12.php
$id =$_post[' id '];
$name =$_post[' Slide_name '];
$IMG =$_post[' img '];
$href =$_post[' Slide_href '];
foreach ($id as $id 1)
{
echo $id 1. "
";
}
foreach ($name as $slide _name)
{
echo $slide _name. "
";
}
foreach ($img as $slide _img)
{
echo $slide _img. "
";
}
foreach ($href as $slide _href)
{
echo $slide _href. "
";
}
$sql = "UPDATE tab SET slide_name= $slide _name,img= $slide _img, where id = $id"; What should I write about SQL?
?>
How do I update a table if I get more than one record in 12.php?
Share to: more
------Solution--------------------
Mainly depends on the data submitted by the form.
You can print out the received data to see Print_r ($_post);
Generally, if the form is Name= "xxx[", the return should be a number of arrays. In other words $id =$_post["id"];
The value to be taken is an array you can update the data in the form of a traversal array, with each record an UPDATE statement.
Like this, huh, no tests, it's almost like that.
$id =$_post[' id '];
$name =$_post[' Slide_name '];
$IMG =$_post[' img '];
$href =$_post[' Slide_href '];
$cnt =count ($id);
for ($i =0; $i + +; $i < $cnt) {
$sql = "UPDATE tab SET slide_name= '". $slide _name[$i]. "', img= '". $slide _img[$i]. "', where id = '. $id [$i].";
}