0

使用查询超过 4 个查询来获取数据库,这四个查询运行正常,但我使用了一个查询来获取 hotel_id,这个 hotel_id 在不同的查询中使用,但是当我运行查询时,查询运行正常但没有得到在while循环中输出,我在代码中的错误是什么.....这个查询正常工作,但是 $query1 = "select hotel_id from menu_master where menu_id=".$id; 但在 $hid = $row['hotel_id']; 无法在 $hid.. 中存储任何值

$query1 = "select hotel_id from menu_master where menu_id=".$id;
                    $res = mysql_query( $query1);
                    while($row=mysql_fetch_array($res))
                    {
                        $hid = $row['hotel_id'];
                    }

                    $query = "select set_rank from menu_master where menu_id = $row_id and hotel_id='".$_REQUEST['hotel_id']."'";
                    //echo $query."<br/>";
                    $result = mysql_query($query);

                    while($row=mysql_fetch_array($result))
                    {
                        $current_rank = $row['set_rank'];
                    }

                    $current_id = $row_id;
                    $new_rank =$_REQUEST['set_rank'];

                     $sql = "select * from menu_master where set_rank = '$new_rank ' and hotel_id='".$_REQUEST['hotel_id']."'" ;    
                     $rs = mysql_query($sql);

                    while($row = mysql_fetch_array($rs))
                         {  
                                $menu_id = $row['menu_id'];
                                $sql="update menu_master 
                                set set_rank=$current_rank where menu_id= $menu_id and hotel_id='".$_REQUEST['hotel_id']."'";

                                mysql_query($sql);

                         }

                                    $sql="update menu_master set 
                                    hotel_id           = '".mysql_real_escape_string($_REQUEST['hotel_id'])."',
                                    menu_name          = '".mysql_real_escape_string($_REQUEST['menu_name'])."',
                                    menu_name_ar       = '".mysql_real_escape_string($_REQUEST['menu_name_ar'])."',
                                    is_active          = '".$is_active."',
                                    set_rank=$new_rank where menu_id= '$current_id' and hotel_id='".$_REQUEST['hotel_id']."'";
                                    mysql_query($sql);
                }
4

2 回答 2

0

试试这个代码

$query1 = "select hotel_id from menu_master where menu_id=".$id;
$row = mysql_fetch_array(mysql_query($query1));
$hid = $row['hotel_id'];
于 2013-05-30T10:17:42.053 回答
0

$query1 = "从 menu_master 中选择 hotel_id,其中 menu_id=".$id;

                $res = mysql_query( $query1);

                while($row1=mysql_fetch_array($res))
                {


                    $hid = $row1['hotel_id'];

                $query = "select set_rank from menu_master where menu_id = $row_id and hotel_id='".$hid."'";
                //echo $query."<br/>";
                $result = mysql_query($query);

                while($row=mysql_fetch_array($result))
                {
                    $current_rank = $row['set_rank'];
                }

                $current_id = $row_id;
                $new_rank =$_REQUEST['set_rank'];

                 $sql = "select * from menu_master where set_rank = '$new_rank ' and hotel_id='".$hid."'" ;    
                 $rs = mysql_query($sql);

                while($row = mysql_fetch_array($rs))
                     {  
                            $menu_id = $row['menu_id'];
                            $sql="update menu_master 
                            set set_rank=$current_rank where menu_id= $menu_id and hotel_id='".$hid."'";

                            mysql_query($sql);

                     }

                                $sql="update menu_master set 
                                hotel_id           = '".mysql_real_escape_string($_REQUEST['hotel_id'])."',
                                menu_name          = '".mysql_real_escape_string($_REQUEST['menu_name'])."',
                                menu_name_ar       = '".mysql_real_escape_string($_REQUEST['menu_name_ar'])."',
                                is_active          = '".$is_active."',
                                set_rank=$new_rank where menu_id= '$current_id' and hotel_id='".$hid."'";
                                mysql_query($sql);
            }
于 2013-05-30T10:41:03.393 回答