旧的php处理语法:
1.
<select name="s" onChange="redirec()">
<option selected>请选择</option> <?php $conn=mysql_connect("localhost","root",""); //连接MySQL服务器 mysql_select_db("PXSCJ",$conn); //选择PXSCJ数据库 mysql_query("SET NAMES gb2312"); //将字符集设为gb2312 $sql="select distinct 专业 from XSB"; // sql 内容 $result=mysql_query($sql); //定义接口 while($row=mysql_fetch_array($result)) //定义循环 { $ZY=$row['专业']; //打印结果 echo "<option value='$ZY'>$ZY</option>"; } ?>
2.新的php 的处理语法
sample 1.
<?php
ini_set('display_errors',1);ini_set('display_startup_errors',1);error_reporting(-1);//print_r($_GET);//exit;$XH=$_GET['XH']; //取得XH的值$KCM=$_GET['KCM']; //取得KCM的值header('Content-Type:text/html;charset=uft8'); //发送header,将编码设为uft8//$db=new PDO("mysql:host=localhost;dbname=PXSCJ","root","");$conn= new mysqli('localhost','root','','PXSCJ'); //连接MySQL服务器if (mysqli_connect_errno($conn)) { echo "Failed to connect to MySQL: " . mysqli_connect_error();}mysqli_set_charset($conn, "utf8"); //将字符集设为uft8$sql="select 成绩 from CJB where 学号='$XH' and 课程号=(select 课程号 from KCB where 课程名='$KCM')"; // sql 内容if ($result=mysqli_query($conn,$sql)) //定义接口{ // Fetch one and one rowwhile ($row= $result->fetch_object()) //定义循环{ printf($row->成绩); //打印结果}// Free result setmysqli_free_result($result);}mysqli_close($conn);
?>
sampe 2.
sample 3: http://www.blogjava.net/nkjava/archive/2015/01/20/422291.html sampe 4: http://www.w3cschool.cn/php/func-mysqli-fetch-row.html