创建下拉菜单和描述更改

时间:2015-01-11 02:24:04

标签: php html mysql list

我目前有一个网页,允许我使用名称,位置,电话号码和说明选项将商家添加到数据库。

因为我有时会在几个列表中将描述修改为相同,所以我想知道如何以一种选择多个列表的方式更改我的代码并添加一个描述来修改所有选择而不必修改每个企业都是单独的。

这是我目前的代码。

<?php include('includes/header.php');?>


<?php include('includes/menu.php');?>

<?php 
    include('includes/function.php');
    include('language/language.php');  

    mysql_query("SET NAMES 'utf8'");    


    if(isset($_GET['directory_d_id']))
    {

        $img_res=mysql_query('SELECT * FROM tbl_directory WHERE d_id=\''.$_GET['directory_d_id'].'\'');
        $img_row=mysql_fetch_assoc($img_res);

            if($img_row['directory_image']!="")
            {
                unlink('images/'.$img_row['directory_image']);
                unlink('images/thumb/'.$img_row['directory_image']);

            }    

        Delete('tbl_directory','d_id='.$_GET['directory_d_id'].'');

        $_SESSION['msg']="18";
         header( "Location:manage_directory");
         exit;
    }

    //Active and Deactive status
    if(isset($_GET['status_deactive_id']))
    {
        $data = array('directory_status'  =>  '0');

        $edit_status=Update('tbl_directory', $data, "WHERE h_id = '".$_GET['status_deactive_id']."'");

         $_SESSION['msg']="12";
         header( "Location:manage_directory");
         exit;
    }
    if(isset($_GET['status_active_id']))
    {
        $data = array('directory_status'  =>  '1');

        $edit_status=Update('tbl_directory', $data, "WHERE h_id = '".$_GET['status_active_id']."'");

        $_SESSION['msg']="11";
         header( "Location:manage_directory");
         exit;
    }


    //Count Records
    $query = "SELECT COUNT(*) as num FROM tbl_directory";
    $total_pages = mysql_fetch_array(mysql_query($query));
    $total_pages = $total_pages['num'];


    $directory_qry="SELECT * FROM tbl_directory
                            LEFT JOIN tbl_category ON tbl_directory.d_cat_id= tbl_category.cid
                            LEFT JOIN tbl_sub_category ON tbl_directory.d_subcat_id= tbl_sub_category.sub_cat_id 
                         ORDER BY tbl_directory.d_id DESC";  

 $directory_result=mysql_query($directory_qry);

?>
<div class="content">

        <div class="header">

            <h1 class="page-title">Manage Listing</h1>
        </div>

            <ul class="breadcrumb">
            <li><a href="dashboard">Home</a> <span class="divider">/</span></li>
            <li class="active">Manage Listing</li>
         </ul>

         <div class="container-fluid">
            <div class="row-fluid">

<div class="btn-toolbar">
    <button class="btn btn-primary" onclick="window.location.href='add_directory?add'"><i class="icon-plus"></i> New Listing</button>

  <div class="btn-group">

  </div>
</div>
<div class="well">

<p style="color:#990000; font-size:14px;" align="center">
                    <?php if(isset($_SESSION['msg'])){ 
                        ?>

                    <div class="alert alert-info">
                         <button type="button" class="close" data-dismiss="alert">×</button>
                         <?php echo $admin_lang[$_SESSION['msg']] ; ?>
                     </div>

                            <?php unset($_SESSION['msg']);      

                    }?>

</p>

<script src="js/jquery-1.11.1.min.js" type="text/javascript"></script>

<script src="js/jquery.dataTables.min.js" type="text/javascript"></script>

<link rel="stylesheet" type="text/css" href="css/jquery.dataTables.css">
<script> 
      $(document).ready(function(){ 
        $('#directory_list').dataTable({                
                    "iDisplayLength":10,
                    "columnDefs": [
                        { "orderable": false, "targets": 4 },
                        { "orderable": false, "targets": 5 },
                        { "orderable": false, "targets": 6 },
                        { "orderable": false, "targets": 7 }
                    ]                
                <?php if($total_pages < 0){?>
                     ,"oLanguage": {
                    "sInfoEmpty": "No data available"
                    }                   
                    <?php }?>   
        }); 
      }); 



</script>


    <table id="directory_list"> 
        <thead> 
          <tr>             
            <th>ID</th>
            <th>Category Name</th>
            <th>Sub Category Name</th>
            <th>Listing Name</th>
            <th>Image</th>
            <th>Status</th>
            <th>Edit</th>
            <th>Delete</th>
          </tr> 
        </thead> 
        <tbody>
        <?php 
                    $i=1;
                    while($directory_row=mysql_fetch_array($directory_result))
                    {
                ?>

        <tr align="center">
          <td><?php echo $i;?></td>
          <td><?php echo $directory_row['category_name'];?></td>
          <td><?php echo $directory_row['sub_cat_name'];?></td>
          <td><?php echo $directory_row['directory_name'];?></td>   
          <td><img src="images/<?php echo $directory_row['directory_image'];?>" height="100" width="100" /></td>  

          <td>
                <?php if($directory_row['directory_status']!="0"){?>
              <a href="manage_directory?status_deactive_id=<?php echo $directory_row['h_id'];?>" title="Change Status"><i class="icon-plus"></i></a>
              <?php }else{?>
              <a href="manage_directory?status_active_id=<?php echo $directory_row['d_id'];?>" title="Change Status"><i class="icon-minus"></i></a>
              <?php }?>
          </td>     
          <td><a href="add_directory?directory_d_id=<?php echo $directory_row['d_id'];?>"><i class="icon-pencil"></i></a></td>

          <td>    <a href="#manage_directory<?php echo $directory_row['d_id'];?>" role="button" data-toggle="modal" title="Delete project"><i class="icon-remove"></i></a>

              <div class="modal small hide fade" id="manage_directory<?php echo $directory_row['d_id'];?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h3 id="myModalLabel">Delete Confirmation</h3>
    </div>
    <div class="modal-body">
        <p class="error-text"><i class="icon-warning-sign modal-icon"></i>Are you sure you want to delete this directorys?
</p>
    </div>
    <div class="modal-footer">
        <button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
        <button class="btn btn-danger" data-dismiss="modal" onclick="window.location.href='manage_directory?directory_d_id=<?php echo $directory_row['d_id'];?>'">Delete</button>
    </div>
</div>

           </td>

          </td>
        </tr>
       <?php $i++;}?>   
      </tbody>
      </table> 

</div>

1 个答案:

答案 0 :(得分:0)

除非我误解了你的问题,否则你问的是如何一次修改数据库的多行。

$description = $_GET['description'];
$businesses = $_GET['businesses'];
mysql_query("UPDATE businesses SET description=$description WHERE name IN ($businesses);");

$businesses可能是这样的结果:

<input type="text" name="businesses" value="<?php print $current_business_being_examined_if_you_have_a_variable_like_this"><br />
<textarea name="description"><?php print $current_description_of_business;?></textarea>

商家是逗号分隔的名单。