Ask more than one update record to submit how to write SQL

Source: Internet
Author: User
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].";


}






  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.