zoukankan      html  css  js  c++  java
  • [PHP] PHP & HTML & JavaScript & MySQL 代码如何互相传值

    1.PHP

      a.PHP -> HTML & JavaScript

      额 超简单,我也要写= =~ 

      html代码中

    <input type=""  readonly="readonly" style='background-color:#DCDCDC' value=<?php echo $perinfo[ID];?> />

       JavaScript代码中

    <script type="text/javascript">
    var ability=<?php echo JSON($array);?>;
    </script>

      b.PHP  <-> MySQL

      php代码中

    <?php
    $dbcnx = @mysql_connect ( "localhost", "root", "1234" );
    if (! $dbcnx) {
        echo ("Unable to connect to the " . "database server at this time.");
        exit ();
    }
    
    if (! @mysql_select_db ( "pms" )) {
        echo ("Unable to locate the joke " . "database at this time.");
        exit ();
    }
    mysql_query ( "SET NAMES 'GB2312'" );
    
    
        $q=mysql_query("select * from ability where ALV = 1"); 
        while($row=mysql_fetch_array($q)){ 
        $array1[] = $row[AName];
    }
    ?>

    2.HTML

      a. HTML -> PHP (POST方式)

      html代码中

    <form id="form" name="form" method="POST" action="do.php">
    <input type="hidden" id="count" name="count" value="1"/>
    <input type="submit" name="Submit" value="Search"/>
    </form>

      do.php 文件代码中

    <?php
    echo $_POST['count'];
    ?>

      b. HTML -> JavaScript

      JavaScript代码中 (可获得,可更改)

    <script type="text/javascript">
    var te = document.getElementById("count");  
    te.value = 1;  
    </script>

    3.JavaScript

      a. JavaScript -> HTML (通用法, 未验证)

      JavaScript代码中 

    <script type="text/javascript">
    function f(){
    var id = "2";
    var a = document.getElementById("a");
    a.href.replace("(n)", id);
    }
    </script>

      html代码

    <a id="a" href="ExportArticle.action?articles=(n)"/>

      b. JavaScript -> PHP

      通过html的转接

      1.JavaScript代码先给html

    <script type="text/javascript">
    var i = 1;
    var te = document.getElementById("count");  
    te.value = i;  
    </script>

      2.html代码给php

    <form id="form" name="form" method="POST" action="do.php">
    <input type="hidden" id="count" name="count" value="1"/>
    <input type="submit" name="Submit" value="Search"/>
    </form>

      3.do.php接收到

    <?php
    echo $_POST['count'];
    ?>
  • 相关阅读:
    Linux 文件系统满,查找大文件的方法
    STM32 HAL库重新设置中断向量表后,无法进入中断的解决方法
    C指针
    vs code 代码片段设置时遇到的几个小问题
    堆排序详解
    Java final和c++ const区别
    白话经典之String字符串详解
    java之SSH框架面试
    JSTL入门指南
    LeetCode(9):Palindrome Number
  • 原文地址:https://www.cnblogs.com/Liangw/p/2708195.html
Copyright © 2011-2022 走看看