php新手请教数据库连接问题

WBOY
Release: 2016-06-23 14:08:58
Original
843 people have browsed it

前几天老师给了一部分代码,让我把php和mysql连接起来,我下载安装了一个wamp,基本页面都可以显示,数据库已建立且有表,以下是config.php里的内容,请问我如何能把keti1表中的内容显示在php页面上?


//######################数据库连接##########################
global $hostname,$dbuser,$dbname,$dbpassword,$jiaoshi_table,$student_table,$user_table,$student_infor,$admin,$pass_admin,$teacher_name,$teacher_pass,$list_num;
 $hostname="localhost";
 $dbname="keti1";
 $dbuser="root";
 $dbpassword="";
 $db=mysql_connect($hostname,$dbuser,$dbpassword) or die("数据库连接错误!");
  mysql_select_db($dbname,$db);
 $jiaoshi_table="jiaoshi";
 $student_table="student";
 $student_infor="jsjxsxx";
 //$user_table="book_user";
 $admin="admin";
 //$query="select * from $user_table where user_name='admin'";
 //mysql_query("set names 'gb2312'");
 //$result=mysql_query($query);
 //$row=mysql_fetch_array($result);
 //$pass=$row['user_pass'];
 $pass_admin="bksbysj001";
 $teacher_name="teacher";
 $teacher_pass="bksbysj";
 $list_num='30';
 
?>


回复讨论(解决方案)

没太懂你说的意思唉  你能把你需要显示什么说清楚么

	//你的数据库叫keti1,哪里有表叫keti1?	//假设连接book_user表	$query="select * from '$user_table' where user_name='admin'";	mysql_query("set names 'gb2312'");	$result=mysql_query($query);	while($row=mysql_fetch_array($result)){		$pass[]=$row['user_pass'];//book_user表中是否有user_pass字段,你自己去看你的表?	}	print_r($pass);//至此你的user_pass字段中的数据会以数组形式输出
Copy after login

谢谢你昨天给我回复的,我还是不太懂,我能不能把我的代码php文件发给你帮我看一下?

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!