当单击PHP中的按钮时,不会选择下拉菜单中的选定值

时间:2019-03-28 18:19:18

标签: php mysqli drop-down-menu while-loop

我正在从两个表“ pizza”和“ size”中选择数据。在“ pizza”表中,“ size”表“ pizza_id,size_id,size,price”中有一个字段名称“ pizza_id,pizza_name,pizza_img”。当我们选择第一个披萨时,其在“尺寸”表中的大小为小,中和大。它显示在下拉菜单中。问题是,当我们单击第一个披萨(小)并单击按钮时显示您选择的是比萨的最后一个(大)披萨。每次选择任何尺寸的披萨,它都表明您选择的是(size_id:3)大披萨,所以我不知道如何解决这个问题。了解我的问题,而不是帮助我,让我陷入困境。谢谢

  $query = "SELECT * FROM pizza";
  $run = mysqli_query($con, $query);

  while($row=mysqli_fetch_array($run)){

        $pizza_id = $row['pizza_id'];
        $pizza_name = $row['pizza_name'];
        $pizza_img = $row['pizza_img'];

  echo "<div class='pizza_details'>
  <img src='admin/img/$pizza_img' width='200px' height='150px'  
  id='profile-image' />
  <div class='desc'>
  <ul>
  <li><span style='color:yellow;'>Name</span> : $pizza_name</li>
  </ul>";


  $q = "SELECT * FROM size where pizza_id='$pizza_id'";
  $r = mysqli_query($con, $q);

  echo "<select name='size'>";

  while ($new=mysqli_fetch_array($r)){

          $size_id = $new['size_id']; 
          $size = $new['size'];
          $price = $new['price'];

   echo"<option value='$size_id'>$size</option>";

   }//End-while loop

   echo"</select>
   <ul><li>
   <a href='pizza.php?add_cart=$pizza_id&size_id=$size_id'>Add to Cart</a>
   </li></ul>
  </div>
  <div class='clear'></div>
  </div>";

  }//End-While Loop

1 个答案:

答案 0 :(得分:0)

var pair = Console.ReadLine().Split(' ');
Dictionary.Add(pair[0], int.Parse(pair[1]))

现在从上方获取所有这些值(product_id,size_id,price),并使用explode函数在select选项中获取多个值。
       

export class NavbarComponent implements OnChanges {
    htmlStyles: string;
    constructor(
        private breakpointObserver: BreakpointObserver
    ) { }
    ngOnChanges(): void {
        // Called after the constructor, initializing input properties, and the first call to ngOnChanges.
        // Add 'implements OnInit' to the class.

        this.breakpointObserver.observe([Breakpoints.Handset, Breakpoints.Medium, Breakpoints.Small])
            .subscribe((state: BreakpointState) => {
                if (state.matches) {
                    this.htmlStyles = 'dummy1';
                } else {
                    this.htmlStyles = 'dummy2';
                }
            });
    }
}