2014-04-29 总结

1、mysql_num_rows(取得结果有多少行的数目)

      $sql1 = "select * from movies";
      $result1 = mysql_query($sql1) or die(mysql_error());
      $count = mysql_num_rows($result1);

2、跨页面传值,隐藏表单域   <input type="hidden">

      <input type="hidden" value="<?php echo $row['id'] ?>" name="id" readonly="readonly"/>

3、页面显示多少条数据

     limit  第几条开始(n-1) , 显示几条

     $sql = "select * from movies limit 0,4"; 页面从第一条显示,一次显示四条

4、表单中偶数行显示一种颜色,奇数行显示一种颜色

    有三种方法:

    CSS:(不推荐,只有CSS3支持)

             odd:奇数行

             even:偶数行

         <style type="text/css">

                 tr:nth-child(even){
                    background: #cad9ea;
                  }

          </style>

      JS:(一般都用)      

             <script   type="text/javascript">       

                  function changeColor(){            

                      var trs = document.getElementsByTagName("tr");          

                           for(var i=0;i<trs.length;i++){  

                                if( i%2 == 0){                  

                                     trs[i].style.background="#e5e8ff";               

                                   }else{                    

                                           trs[i].style.background="#edd8f2";               

                                          }            

                                 }       

                   }        

               window.onload=changeColor;

        </script>

    PHP:(不怎么用)

           <?php
                  if($n %2 == 0){
            ?>
            <tr style="background: #cad9ea">
            <?php
                }else{
            ?>
            <tr>
             <?php
                }
             ?>

5、传值时,最好用数字,然后字母,最重要的是不要用中文

6、intval()转换成整型

      $totalPage = $count % $pageSize == 0 ? intval($count / $pageSize) :  intval($count / $pageSize) + 1;

7、在页面上修改数据值

    首先:

            <form action="movie_update.php" method="post">
            <input type="hidden" value="<?php echo $row['id'] ?>" name="id" readonly="readonly"/>
            电影名称: <input type="text" value="<?php echo $row['movieName'] ?>" name="movieName"  /> <br/>
            主    演: <input type="text" value="<?php echo $row['actor'] ?>" name="actor"  /> <br/>
            <input type="submit" name="submit" value="修改"/>
            </form>

   要修改的数据给设定一个name值,在要跳转的页面:

          <?php
              $conn = mysql_connect("localhost","root","") or die("链接数据库失败");
               mysql_select_db("test");
               mysql_query("set names 'utf8'");
               if(@$_POST['submit']){
              $id = $_POST['id'];
              $movieName = $_POST['movieName'];
              $actor = $_POST['actor'];
              $sql = "UPDATE `movies` SET `movieName`='$movieName',`actor`='$actor' WHERE id=$id";
             $r = mysql_query($sql);
            if($r){
               echo "<script>location.href='movie_a.php'</script>";
             }
        }
      ?>

  

    

             

          

 

posted @ 2014-04-29 20:28  失忆^ Dreams  阅读(111)  评论(0编辑  收藏  举报