
正文
php查询数据库并显示 php查询数据库并显示,为什么不能显示主键
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
php如何查询数据库表中的数据并显示
这个简单啊php查询数据库并显示!
首页做个前台输入姓名和会员卡信息的页面php查询数据库并显示,php查询数据库并显示我做个简单的页面给你看
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
html xmlns="
head
meta http-equiv="Content-Type" content="text/html; charset=utf-8" /
title会员查询系统/title
/head
body
form id="form1" name="form1" method="post" action="test.php"
p
label for="name"/label
input type="text" name="name" id="name" /
/p
p
label for="vipid"/label
input type="text" name="vipid" id="vipid" /
/p
p
input type="submit" name="button" id="button" value="查询" /
/p
/form
/body
/html
然后我给你一个test.php的文件代码:
?php
$name = trim($_POST['name']);
$vipid = trim($_POST['vipid']);
$con = mysql_connect("127.0.0.1","数据库用户名","数据库密码");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$a = mysql_select_db("数据库名字", $con);
$sql = "select * from kh_customer where name = '$name' and vipid = '$vipid'";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
echo $row['name'] . " " . $row['data'];
echo "br /";
}
mysql_close($con);
?
页面美化自己去搞php查询数据库并显示!只能帮你这么多了
相关问答
Q1: PHP如何查询数据并显示结果。
这个简单啊php查询数据库并显示!
首页做个前台输入姓名和会员卡信息php查询数据库并显示的页面php查询数据库并显示,我做个简单php查询数据库并显示的页面给你看
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""
html xmlns=""
head
meta http-equiv="Content-Type" content="text/html; charset=utf-8" /
title会员查询系统/title
/head
body
form id="form1" name="form1" method="post" action="test.php"
p
label for="name"/label
input type="text" name="name" id="name" /
/p
p
label for="vipid"/label
input type="text" name="vipid" id="vipid" /
/p
p
input type="submit" name="button" id="button" value="查询" /
/p
/form
/body
/html
然后我给你一个test.php的文件代码:
?php
$name = trim($_POST['name']);
$vipid = trim($_POST['vipid']);
$con = mysql_connect("127.0.0.1","数据库用户名","数据库密码");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$a = mysql_select_db("数据库名字", $con);
$sql = "select * from kh_customer where name = '$name' and vipid = '$vipid'";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
echo $row['name'] . " " . $row['data'];
echo "br /";
}
mysql_close($con);
?
页面美化自己去搞!只能帮你这么多php查询数据库并显示了
Q2: php查询数据库并在网页上输出结果
$sql = 'SELECT COUNT( * ) FROM DAY WHERE id_u =1' ;
$resault = $db-getAll($sql);
//
function getAll($sql)
{
$res = $this-query($sql);
if ($res !== false)
{
$arr = array();
while ($row = mysql_fetch_assoc($res))
{
$arr[] = $row;
}
return $arr;
}
else
{
return false;
}
}
//
function query($sql, $type = '')
{
if ($this-link_id === NULL)
{
$this-connect($this-settings['dbhost'], $this-settings['dbuser'], $this-settings['dbpw'], $this-settings['dbname'], $this-settings['charset'], $this-settings['pconnect']);
$this-settings = array();
}
if ($this-queryCount++ = 99)
{
$this-queryLog[] = $sql;
}
if ($this-queryTime == '')
{
if (PHP_VERSION = '5.0.0')
{
$this-queryTime = microtime(true);
}
else
{
$this-queryTime = microtime();
}
}
/* 当当前php查询数据库并显示的时间大于类初始化时间php查询数据库并显示的时候php查询数据库并显示,自动执行 ping 这个自动重新连接操作 */
if (PHP_VERSION = '4.3' time() $this-starttime + 1)
{
mysql_ping($this-link_id);
}
if (!($query = mysql_query($sql, $this-link_id)) $type != 'SILENT')
{
$this-error_message[]['message'] = 'MySQL Query Error';
$this-error_message[]['sql'] = $sql;
$this-error_message[]['error'] = mysql_error($this-link_id);
$this-error_message[]['errno'] = mysql_errno($this-link_id);
$this-ErrorMsg();
return false;
}
if (defined('DEBUG_MODE') (DEBUG_MODE 8) == 8)
{
$logfilename = $this-root_path . DATA_DIR . '/mysql_query_' . $this-dbhash . '_' . date('Y_m_d') . '.log';
$str = $sql . "\n\n";
if (PHP_VERSION = '5.0')
{
file_put_contents($logfilename, $str, FILE_APPEND);
}
else
{
$fp = @fopen($logfilename, 'ab+');
if ($fp)
{
fwrite($fp, $str);
fclose($fp);
}
}
}
return $query;
}
Q3: PHP实现按条件查询 数据库内容并在当前页面显示,如下图,谢谢提供下思路
页面加载时 distinct 一下班级,把得到的列表加载到班级的 dropdownlist里,至于性别的直接手动添加男女就行了。
点击查询的时候 select * from xxx where 班级=班级dorpdownlist.text and 性别=性别dorpdownlist.text
Q4: 如何用php获取数据库信息并显示
获取ppq数据库php查询数据库并显示的所有表名的代码php查询数据库并显示:
?php
$server='localhost';
$user='root';
$pass='12345';
$dbname='ppq';
$conn=mysql_connect($server,$user,$pass);
if(!$conn)
die("数据库系统连接失败!");
$result=mysql_list_tables($dbname);
if(!$result)
die("数据库连接失败!");
while($row=mysql_fetch_row($result))
{
echo
$row[0]."
";
}
mysql_free_result($result);
?
mysql_list_tables
(PHP
3,
PHP
4
,
PHP
5)
mysql_list_tables
--
列出
MySQL
数据库中的表
说明
resource
mysql_list_tables
(
string
database
[,
resource
link_identifier])
mysql_list_tables()
接受一个数据库名并返回和
mysql_query()
函数很相似的一个结果指针。用
mysql_fetch_array()或者用mysql_fetch_row()来获得一个数组php查询数据库并显示,数组的第0列就是数组名,当获取不到时
mysql_fetch_array()或者用mysql_fetch_row()返回
FALSE。
Q5: PHP在数据库中查询并且显示图片
一般不向数据库插入图片 而是插入图片的src 通过src找到图片然后显示。
?php
session_start();
//array数组中放图片的格式
$uptypes = array("image/jpg","image/jpeg","image/png","image/pjpeg","image/gif","image/bmp","image/x-png");
$files =$_FILES["uppic"];
if($files["size"]2097152){ //图片大小判断
echo "上传图片不能大于2M";
echo "meta http-equiv='REFRESH' CONTENT='1;URL=pic.php'";
exit;
}
$ftype =$files["type"];
if(!in_array($ftype,$uptypes)){ //图片格式判断
echo "上传的图片文件格式不正确";
echo "meta http-equiv='REFRESH' CONTENT='1;URL=pic.php'";
}
$fname = $files["tmp_name"]; //在服务器临时存储名称
$image_info = getimagesize($fname);
$name = $files["name"];
$str_name = pathinfo($name); //以数组的形式返回文件路劲的信息
$extname = strtolower($str_name["extension"]); //把字符串改为小写 extensiorn扩展名
$upload_dir = "upload/"; //upload文件夹
$file_name = date("YmdHis").rand(1000,9999).".".$extname;
$str_file = $upload_dir.$file_name; //文件目录
//存入数据库
$con=mysql_connect("localhost","root","");
if(!$con){
die(("数据库连接失败").mysql_error());
}
mysql_select_db("mywork",$con);
$sql="update user set picpath='$str_file' where user_name='$username'"; //将图片地址插入数据库mywork
mysql_query($sql,$con);
mysql_close($con);
if(!file_exists($upload_dir)){
mkdir($upload_dir); //创建目录 成功则返回true 失败则返回flase
}
if(!move_uploaded_file($files["tmp_name"],$str_file)){ //将上传的文件移动到新的目录 要移动文件和文件新目录 成功则返回true
echo "图片上传失败";
echo "meta http-equiv='REFRESH' CONTENT='1;URL=插入失败后希望跳转的页面";
}
else{
//echo "img src=".$str_file."";
echo "图片上传成功";
echo "meta http-equiv='REFRESH' CONTENT='1;URL=插入成功希望挑战的页面";
}
关于php查询数据库并显示和php查询数据库并显示,为什么不能显示主键的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。






