纯php打造的tab选项卡效果代码,php与mysql基础教程

2019-07-27 作者:yzc216.com官网   |   浏览(101)

1.根据get判断,获取get生成css

  1.php  连接数据库的示例。
  2.php  关闭数据库连接。
  3.php  执行sql语句。
  4.php  获取sql语句执行错误的信息。
  5.php  获取查询结果集。
  6.php  获取结果集中的所有记录。
  7.php  用php程序显示表中数据。
  8.php  分页显示数据。
  9.html  提交用户信息的html页面。
  10.php  数据插入数据库。
  11.php  显示数据信息的php程序。
  12.php  添加删除链接的php程序。
  13.php  删除数据库数据。

复制代码 代码如下:

*/
 // 1.php  连接数据库的示例。

<style type="text/css">
<?php
if(!isset($_GET['city_id']))
{
$city_id = 12;
}
else
{
$city_id = $_GET['city_id'];
}
echo '.a'.$city_id.'
{
color:red;
}
';
for($i=12;$i<=16;$i )
{
if($i != $city_id)
{
if ($i != 12 )
{
echo '.list'.$i.'{
background-image:url("image/style/bg.gif");
}';
}
else
{
echo '.list'.$i.'
{
background-image:url("image/style/left_bg.gif");
}
';
}
}
else
{
if($city_id != 12)
{
echo '.list'.$city_id.'
{
background-image:url("image/style/on.gif");
}
';
}else
{
echo '.list'.$city_id.'{
background-image:url("image/style/recuit_title.gif");
}';
}
}
}
?>
</style>

 代码如下

2.点击的时候,就可以打开链接

$host = 'localhost';
$user_name = 'root';
$password = 'admin';

复制代码 代码如下:

$conn = mysql_connect($host,$user_name,$password);
if(!$conn)
{
    die('数据库连接失败:<br/>'.mysql_error());
}
echo '数据库连接成功!';

<div class="recuit_title" >
<ul id="recuit_li">
<li class="list12"><a class="a12" href="test.php?city_id=12">北京</a></li>
<?php
include_once ("config/db.inc.php");
$recuit_city_select = "select * from cdb_plugins_city where city_id in(13,14,15,16)";
$recuit_city_query = mysql_query ( $recuit_city_select );
while ( $recuit_city_row = mysql_fetch_assoc ( $recuit_city_query ) ) {
$cid = $recuit_city_row['city_id'];
echo '<li class="list'.$recuit_city_row['city_id'].'" ><a class="a'.$recuit_city_row['city_id'].'" href="test.php?city_id=' . $recuit_city_row ['city_id'] . '">' . $recuit_city_row ['city_name'] . '</a></li>';
}
?>
</ul>
<span class="more_recuit_info">
<a href="../job.php?action=recuit_list&cid=12" onClick="parent.showWindow('recuit_list',this.href);return false;">更多招募信息</a>
</span>
</div>
<div class="recuit_content">
<table width="100%">
<?php
if(!$_GET['city_id'])
{

 

$recuit_content_select = "select * from cdb_plugins_recuit where city_id= 12 limit 0,8";
$recuit_content_query = mysql_query($recuit_content_select);
while($recuit_content_row = mysql_fetch_assoc($recuit_content_query))
{
echo '<tr height="25">
<td>
<a onclick="parent.showWindow('.''recuit_info','.'this.href'.');return false;"'.'" href="../job.php?action=recuit_info&recuit_id='.$recuit_content_row['recuit_id'].'">'.$recuit_content_row['recuit_name'].'</a>
</td>
<td width="80" align="right" style="color:#0080ff;font-size:12px;">
'.$recuit_content_row['username'].'  
</td>
</tr>';
}
}
else
{
$recuit_content_select = "select * from cdb_plugins_recuit where city_id={$_GET['city_id']} limit 0,10";
$recuit_content_query = mysql_query($recuit_content_select);
while($recuit_content_row = mysql_fetch_assoc($recuit_content_query))
{
echo '<tr>
<td><a onclick="parent.showWindow('.''recuit_info','.'this.href'.');return false;"'.'" href="../job.php?action=recuit_info&recuit_id='.$recuit_content_row['recuit_id'].'">'.$recuit_content_row['recuit_name'].'</a></td>
<td width="80" align="right" style="color:#0080ff;font-size:12px;">'.$recuit_content_row['username'].'  </td>
</tr>';
}
}
?>
</table>
</div>
<div class="recuit_footer">
<?php
include_once ("../include/common.inc.php");
$recuit_query = mysql_query("select * from cdb_plugins_recuit_userinfo where uid=$discuz_uid");
$recuit_rows = mysql_fetch_assoc($recuit_query);
if($recuit_rows['uid'] == '')
{
echo '<a href="../job.php?action=recuit" onclick="parent.showWindow('.''recuit''.',this.href);return false;"><img src="image/style/recuit_frm_input.gif" border="0" /></a>  ';
}
else
{
echo '<a href="../job.php?action=edit_recuit" onclick="parent.showWindow('.''edit_recuit''.',this.href);return false;"><img src="image/style/edit_recuit.gif" border="0"/><a>  ';
}
?>
</div>

// 2.php  关闭数据库连接。

您可能感兴趣的文章:

  • javascript实现tabs选项卡切换效果(自写原生js)
  • js实现tab选项卡函数代码
  • Vue.js组件tabs实现选项卡切换效果
  • 使用vue.js写一个tab选项卡效果
  • js tab 选项卡
  • 原生js实现tab选项卡切换
  • 跨浏览器通用、可重用的选项卡tab切换js代码
  • 4种JavaScript实现简单tab选项卡切换的方法
  • Vue.js组件tab实现选项卡切换
  • JavaScript插件Tab选项卡效果

 代码如下

$host = 'localhost';
$user_name = 'root';
$password = 'admin';

$conn = mysql_connect($host,$user_name,$password);
if(!$conn)
{
    die('数据库连接失败:'.mysql_error());
}
echo '数据库连接成功!';

if(mysql_close($conn))
{
    echo '<br/>........<br/>';
    echo '到数据库的连接已经成功关闭';
}

 

 

 
  //3.php  执行sql语句。  

 

 代码如下

$host = 'localhost';
$user_name = 'root';
$password = 'admin';

$conn = mysql_connect($host,$user_name,$password);
if(!$conn)
{
    die('数据库连接失败:'.mysql_error());
}
mysql_select_db('test');

$sql = 'select id,name,city from users';
$result = mysql_query($sql);

if($result)
{
    echo 'sql语句:' . $sql . '<br/>已经成功执行!';
    $num = mysql_num_rows($result);    //调用函数mysql_num_row()获得select语句查询结果的行数
    echo '<br/>该sql语句查询到<b>'.$num.'</b>行数据';
}

mysql_close($conn);  

//4.php  获取sql语句执行错误的信息。

 代码如下

$host = 'localhost';
$user_name = 'root';
$password = 'admin';

$conn = mysql_connect($host,$user_name,$password);
if(!$conn)
{
    die('数据库连接失败:'.mysql_error());
}
mysql_select_db('test');

$sql = 'select id,name,city,gender from users';

//这里使用mysql_error()获取sql语句执行出错时的相关信息
$result = mysql_query($sql) or die("<br/>error: <b>".mysql_error()."</b><br/><br/><br/>产生问题的sql<br/>".$sql);

if($result)
{
    echo 'sql语句:' . $sql . '<br/>已经成功执行!';
}

mysql_close($conn);

 

 

  //5.php  获取查询结果集。

 

 代码如下

$host = 'localhost';
$user_name = 'root';
$password = 'admin';

$conn = mysql_connect($host,$user_name,$password);
if(!$conn)
{
    die('数据库连接失败:'.mysql_error());
}
mysql_select_db('test');

$sql = 'select id,name,city from users';

$result = mysql_query($sql) or die("<br/>error: <b>".mysql_error()."</b><br/>产生问题的sql:".$sql);

if($num = mysql_num_rows($result))
{
    $row = mysql_fetch_array($result);
    echo '<pre>';
    print_r($row);
}

mysql_close($conn);
  //6.php  获取结果集中的所有记录。
$host = 'localhost';
$user_name = 'root';
$password = 'admin';

$conn = mysql_connect($host,$user_name,$password);
if(!$conn)
{
    die('数据库连接失败:'.mysql_error());
}
mysql_select_db('test');

$sql = 'select id,name,city from users';

$result = mysql_query($sql) or die("<br/>error: <b>".mysql_error()."</b><br/>产生问题的sql:".$sql);

if($num = mysql_num_rows($result))
{
    echo '<pre>';
    while($row = mysql_fetch_array($result,mysql_assoc))
    {
        print_r($row);
    }
}

mysql_close($conn);  

 

 

//7.php  用php程序显示表中数据。

 

 代码如下

$host = 'localhost';
$user_name = 'root';
$password = 'admin';

$conn = mysql_connect($host,$user_name,$password);
if(!$conn)
{
    die('数据库连接失败:'.mysql_error());
}
mysql_select_db('test');

$sql = 'select id,name,city,created_time from users';

$result = mysql_query($sql) or die("<br/>error: <b>".mysql_error()."</b><br/>产生问题的sql:".$sql);
?>
<html>
<head>
<title>13-7.php</title>
</head>
<center>

<body>
<table width="75%" border="0" cellpadding="0" cellspacing="1" bgcolor="#7b7b84">
    <tr bgcolor="#8bbcc7">
        <td height="33"><div align="center"><strong>用户id</strong></div></td>
        <td><div align="center"><strong>用户名称</strong></div></td>
        <td><div align="center"><strong>来自城市</strong></div></td>
        <td><div align="center"><strong>注册时间</strong></div></td>
    </tr>

<?php
if($num = mysql_num_rows($result))
{
    while($row = mysql_fetch_array($result,mysql_assoc))
    {
?>
    <tr bgcolor="#ffffff">
        <td height="22" align="right"><?php echo $row['id']; ?> </td>
        <td height="22"> <?php echo $row['name']; ?> </td>
        <td height="22"> <?php echo $row['city']; ?> </td>
        <td height="22"> <?php echo $row['created_time']; ?> </td>
    </tr>
<?php
    }
}
mysql_close($conn);
?>

</table>
</body>
</center>
</html>  

 

 

//8.php  分页显示数据。

 

 代码如下

$host = 'localhost';
$user_name = 'root';
$password = 'admin';

$conn = mysql_connect($host,$user_name,$password);
if(!$conn)
{
    die('数据库连接失败:'.mysql_error());
}
mysql_select_db('test');

if(isset($_get['page']))     //由get方法获得页面传入当前页数的参数
{
    $page = $_get['page'];
}
else
{
    $page = 1;
}
$page_size = 2;              //每页显示两条数据

//获取数据总量
$sql = 'select * from users';
$result = mysql_query($sql);
$total = mysql_num_rows($result);

//开始计算总页数
if($total)
{
    //如果总数据量小于$page_size,那么只有一页
    if($total < $page_size)
        $page_count = 1;
    //如果有余数,则总页数等于总记录数除以页数的结果取整再加1
    if($total % $page_size)
    {
        $page_count = (int)($total/$page_size) 1;
    }
    //如果没有余数,则页数等于总数据量除以每页数的结果
    else
    {
        $page_count = $total/$page_size;
    }
}
else
{
    $page_count = 0;
}
//翻页链接
$turn_page = '';
if($page == 1)
{
    $turn_page .= '首页 | 上一页 |';
}
else
{
    $turn_page .= '<a href=13-8.php?page=1> 首页</a> | <a href=13-8.php?page='.($page-1).'> 上一页 </a> |';
}
if($page == $page_count || $page_count == 0)
{
    $turn_page .= ' 下一页 | 尾页';
}
else
{
    $turn_page .= '<a href=13-8.php?page='.($page 1).'> 下一页 </a>|<a href=13-8.php?page='.$page_count.'> 尾页 </a>';
}

$sql = 'select id,name,city,created_time from users limit '. ($page-1)*$page_size .', '.$page_size;
$result = mysql_query($sql) or die("<br/>error: <b>".mysql_error()."</b><br/>产生问题的sql:".$sql);
?>
<html>
<head>
<title>13-8.php</title>
</head>
<center>

<body>
<table width="75%" border="0" cellpadding="0" cellspacing="1" bgcolor="#7b7b84">
    <tr bgcolor="#8bbcc7">
        <td height="33"><div align="center"><strong>用户id</strong></div></td>
        <td><div align="center"><strong>用户名称</strong></div></td>
        <td><div align="center"><strong>来自城市</strong></div></td>
        <td><div align="center"><strong>注册时间</strong></div></td>
    </tr>

<?php
if($num = mysql_num_rows($result))
{
    while($row = mysql_fetch_array($result,mysql_assoc))
    {
?>
    <tr bgcolor="#ffffff">
        <td height="22" align="right"><?php echo $row['id']; ?> </td>
        <td height="22"> <?php echo $row['name']; ?> </td>
        <td height="22"> <?php echo $row['city']; ?> </td>
        <td height="22"> <?php echo $row['created_time']; ?> </td>
    </tr>
<?php
    }
}
echo $turn_page.'<br/><br/>';
mysql_close($conn);
?>

</table>
</body>
</center>
</html>  

 

 

//9.html  提交用户信息的html页面。  

 

 代码如下

<html>
<head>
<title>13-9.html</title>
</head>

<body>
<b>提交用户信息</b>
<form name="form" method="post" action="13-10.php">
    <table width="75%" border="0" cellpadding="0" cellspacing="2">
        <tr>
            <td width="24%" height="29">用户名:</td>
            <td width="76%"><input name="user_name" type="text" id="user_name" size="20"></td>
        </tr>
        <tr>
        <td height="25">来自城市:</td>
        <td>
     <select name="city">
     <option value="beijing">北京</option>
     <option value="london">伦敦</option>
     <option value="newyork">纽约</option>
     <option value="paris">巴黎</option>
     <option value="rome">罗马</option>
        </select>
  </td>
        </tr>
        <tr>
            <td height="31">
            <input type="submit" name="submit" value="提交"></td>
            <td> </td>
        </tr>
    </table>
</form>
</body>
</html>

  //10.php  数据插入数据库。
  <?php
$host = 'localhost';
$user_name = 'root';
$password = 'admin';

$name = $_post['user_name'];
$city = $_post['city'];

if(empty($name) || trim($name)=='')
{
    echo '请填写用户名!<a href="13-9.html">返回</a>';
    exit;
}

$conn = mysql_connect($host,$user_name,$password);
if(!$conn)
{
    die('数据库连接失败:'.mysql_error());
}
mysql_select_db('test');

$sql = "insert into users set id=7,name='" . $name . "',city='" . $city . "',created_time=now()";
mysql_query($sql) or die("<br/>error: <b>".mysql_error()."</b><br/>sql:".$sql);
mysql_close($conn);

echo '数据插入成功,打开<a href="13-7.php">13-7.php</a>查看数据';
?>

 

 

  //11.php  显示数据信息的php程序。  

 

 代码如下

<?php
$host = 'localhost';
$user_name = 'root';
$password = 'admin';
$arr_city = array('beijing'=>'北京','newyork'=>'纽约','paris'=>'巴黎','london'=>'伦敦','rome'=>'罗马');

$conn = mysql_connect($host,$user_name,$password);
if(!$conn)
{
yzc216.com官网,    die('数据库连接失败:'.mysql_error());
}
mysql_select_db('test');

if(!isset($_get['uid']))
{
    echo '参数错误!';
    exit;
}
$id = $_get['uid'];

$sql = "select * from users where id=$id";
$result = mysql_query($sql) or die("<br/>error: <b>".mysql_error()."</b><br/>sql:".$sql);
if(!mysql_num_rows($result))
{
    echo '用户id错误!';
    exit;
}

$row = mysql_fetch_array($result);

$name = $_post['user_name'];
$city = $_post['city'];
if(!empty($name) || trim($name)!='')
{
    $sql = "update users set name='" . $name . "',city='" . $city . "' where id=$id";
    mysql_query($sql) or die("<br/>error: <b>".mysql_error()."</b><br/>sql:".$sql);
    mysql_close($conn);

    echo '数据修改成功,打开<a href="13-7.php">13-7.php</a>查看数据';
    exit;
}
?>

<html>
<head>
<title>13-11.php</title>
</head>

<body>
<b>修改用户信息</b>
<form name="form" method="post" action="13-11.php?uid=<?php echo $id; ?>">
    <table width="75%" border="0" cellpadding="0" cellspacing="2">
        <tr>
            <td width="24%" height="29">用户名:</td>
            <td width="76%"><input name="user_name" type="text" id="user_name" size="20" value="<?php echo $row['name']; ?>"></td>
        </tr>
        <tr>
        <td height="25">来自城市:</td>
        <td>
        <select name="city">
        <?php
        foreach($arr_city as $k=>$v)
        {
            $option = ($row['city'] == $k) ? '<option value="'.$k.'" selected>'.$v.'</option>' : '<option value="'.$k.'">'.$v.'</option>';
            echo $option.' ';
        }   
        ?>
        </select>
        </td>
        </tr>
        <tr>
        <td>注册时间:</td>
        <td><?php echo $row['created_time']; ?></td>
        </tr>
        <tr>
            <td height="31">
            <input type="submit" name="submit" value="修改"></td>
            <td> </td>
        </tr>
    </table>
</form>
</body>
</html>  

 

 

// 12.php  添加删除链接的php程序。  

 

 代码如下

<?php
$host = 'localhost';
$user_name = 'root';
$password = 'admin';

$conn = mysql_connect($host,$user_name,$password);
if(!$conn)
{
    die('数据库连接失败:'.mysql_error());
}
mysql_select_db('test');

$sql = 'select id,name,city,created_time from users';

$result = mysql_query($sql) or die("<br/>error: <b>".mysql_error()."</b><br/>产生问题的sql:".$sql);
?>
<html>
<head>
<title>13-12.php</title>
<script language="网页特效">

</script>
</head>
<center>

<body>
<table width="75%" border="0" cellpadding="0" cellspacing="1" bgcolor="#7b7b84">
    <tr bgcolor="#8bbcc7">
        <td height="33"><div align="center"><strong>用户id</strong></div></td>
        <td><div align="center"><strong>用户名称</strong></div></td>
        <td><div align="center"><strong>来自城市</strong></div></td>
        <td><div align="center"><strong>注册时间</strong></div></td>
        <td><div align="center"><strong>操作</strong></div></td>
    </tr>

<?php
if($num = mysql_num_rows($result))
{
    while($row = mysql_fetch_array($result,mysql_assoc))
    {
?>
    <tr bgcolor="#ffffff">
        <td height="22" align="right"><?php echo $row['id']; ?> </td>
        <td height="22"> <?php echo $row['name']; ?> </td>
        <td height="22"> <?php echo $row['city']; ?> </td>
        <td height="22"> <?php echo $row['created_time']; ?> </td>
        <td height="22"> <a onclick="javascript:if(confirm('确定要删除用户信息吗?')) return true; else return false;" href="13-13.php?id=<?php echo $row['id']; ?>">删除</a> </td>
    </tr>
<?php
    }
}
mysql_close($conn);
?>

</table>
</body>
</center>
</html>  

/

 

/13.php  删除数据库数据。  

 

 代码如下

<?php
if(!isset($_get['id']))
{
    echo '参数错误!';
    exit;
}

$id = $_get['id'];
if(empty($id))
{
    echo '用户id不能为空!';
    exit;
}

$host = 'localhost';
$user_name = 'root';
$password = 'admin';

$conn = mysql_connect($host,$user_name,$password);
if(!$conn)
{
    die('数据库连接失败:'.mysql_error());
}
mysql_select_db('test');

//先判断是否存在该id的用户
$sql = "select * from users where id=$id";
$result = mysql_query($sql) or die("<br/>error: <b>".mysql_error()."</b><br/>sql:".$sql);
if(!mysql_num_rows($result))
{
    echo '用户id错误!';
    exit;
}

//删除用户数据
$sql = "delete from users where id=$id";
mysql_query($sql) or die("<br/>error: <b>".mysql_error()."</b><br/>sql:".$sql);
mysql_close($conn);

echo '数据删除成功,返回<a href="13-12.php">13-12.php</a>查看数据';
?>

本文由yzc216亚洲城发布于yzc216.com官网,转载请注明出处:纯php打造的tab选项卡效果代码,php与mysql基础教程

关键词: yzc216亚洲城 yzc216.com官网