简单的php代码?用php做一个简单的网页
各位老铁们好,相信很多人对简单的php代码都不是特别的了解,因此呢,今天就来为大家分享下关于简单的php代码以及用php做一个简单的网页的问题知识,还望可以帮助大家,解决大家的一些困惑,下面一起来看看吧!
php语言里的一些很简单的代码解释。求解释
第一行,将关键字和指向的页面装入一个数组,可用做url链接,portal指向portal.php
第二行,用点分割指定的系统变量$_SERVER['HTTP_HOST']
第三行,是一个url链接,目标页面为forum.php。在?后面传递“变量=值”对(如:mod=group),
&用来连接这些变量和值对。
第四行,是一组嵌套的三元运算符。类似于if...else判断。
*****
表达式1?表达式2:表达式3
(1)条件表达式的执行顺序:先求解表达式1,若为非0(真)则求解表达式2,此时表达式2的值就作为整个表达式的值。
若表达式1的值为0(假),则求解表达式3,表达式3的值就是整个条件表达式的值。
(2)条件表达式优先于赋值运算符,max=(a>b)?a:b则先求解条件表达式在赋给max。
(3)自右向左运算
a>b? a:c>d? c:d
应该是
a>b? a:(c>d? c:d)
******
最好不要在php中使用多个三元操作符。
使用多个时添加括号:
$a=1>0?1:(2==0?2:(3<0?3:0));
请php 简单 产品分类代码
商品分类展示
设置商品分类显示不仅可使该购物系统的所有商品都分门别类的显示出来,而且为用户选择商品提供了很大的方便。首先应该建立一个单独的type表用来存储商品大类,之后在shangpin表中增加一个typeid字段,该字段中存储的内容是商品大类id值,利用这个值就可以确定该商品属于那一类。商品分类展示是在showfenlei.php中完成的,代码如下:
<!--*******************************showfenlei.php*******************************-->
<?php
include("top.php");
?>
<table width="800" height="438" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="200" height="438" valign="top" bgcolor="#E8E8E8"><div align="center">
<?php include("left.php");?>
</div></td>
<td width="10" background="images/line2.gif"></td>
<td width="590" valign="top"><table width="590" height="20" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><div align="left">
<?php
$sql=mysql_query("select* from type order by id desc",$conn);
$info=mysql_fetch_object($sql);
if($info==false)
{
echo"本站暂无商品!";
}
else
{
do
{
echo"<a href='showfenlei.php?id=".$info->id."'>".$info->typename."</a>";
}
while($info=mysql_fetch_object($sql));
}
?>
</div></td>
</tr>
</table>
<?php
if($_GET[id]=="")
{
$sql=mysql_query("select* from type order by id desc limit 0,1",$conn);
$info=mysql_fetch_array($sql);
$id=$info[id];
}
else
{
$id=$_GET[id];
}
$sql1=mysql_query("select* from type where id=".$id."",$conn);
$info1=mysql_fetch_array($sql1);
$sql=mysql_query("select count(*) as total from shangpin where typeid='".$id."' order by addtime desc",$conn);
$info=mysql_fetch_array($sql);
$total=$info[total];
if($total==0)
{
echo"<div align='center'>本站暂无该类产品!</div>";
}
else
{
?>
<table width="550" height="25" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><div align="left"><span style="color:#666666; font-weight: bold"><span style="color:#000000">本类商品>></span><?php echo$info1[typename];?></span>
</div></td>
</tr>
</table>
<table width="550" height="10" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td background="images/line1.gif"></td>
</tr>
</table>
<table width="550" height="70" border="0" align="center" cellpadding="0" cellspacing="0">
<?php
$pagesize=10;
if($total<=$pagesize)
{
$pagecount=1;
}
if(($total%$pagesize)!=0)
{
$pagecount=intval($total/$pagesize)+1;
}
else
{
$pagecount=$total/$pagesize;
}
if(($_GET[page])=="")
{
$page=1;
}
else
{
$page=intval($_GET[page]);
}
$sql1=mysql_query("select* from shangpin where typeid=".$id." order by addtime desc limit".($page-1)*$pagesize.",$pagesize",$conn);
while($info1=mysql_fetch_array($sql1))//显示商品信息
{
?>
……
<?php
}
?>
</table>
<table width="550" height="25" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><div align="right">本站共有该类商品
<?php
echo$total;
?>
件每页显示<?php echo$pagesize;?>件第<?php echo$page;?>页/共<?php echo$pagecount;?>页
<?php
if($page>=2)//商品分页显示
{
?>
<a rel="external nofollow" href="showfenlei.php?id=<?php echo$id;?>&page=1" title="首页"><font face="webdings"> 9</font></a>
<a rel="external nofollow" rel="external nofollow" href="showfenlei.php?id=<?php echo$id;?>&page=<?php echo$page-1;?>" title="前一页"><font face="webdings"> 7</font></a>
<?php
}
if($pagecount<=4){
for($i=1;$i<=$pagecount;$i++){
?>
<a rel="external nofollow" rel="external nofollow" href="showfenlei.php?id=<?php echo$id;?>&page=<?php echo$i;?>"><?php echo$i;?></a>
<?php
}
}
else
{
for($i=1;$i<=4;$i++){
?>
<a rel="external nofollow" rel="external nofollow" href="showfenlei.php?id=<?php echo$id;?>&page=<?php echo$i;?>"><?php echo$i;?></a>
<?php
}
?>
<a rel="external nofollow" rel="external nofollow" href="showfenlei.php?id=<?php echo$id;?>&page=<?php echo$page-1;?>" title="后一页"><font face="webdings"> 8</font></a>
<a rel="external nofollow" href="showfenlei.php?id=<?php echo$id;?>&page=<?php echo$pagecount;?>" title="尾页"><font face="webdings">:</font></a>
<?php
}
?>
</div></td>
</tr>
</table>
<?php
}
?>
</td>
</tr>
</table>
<?php
include("bottom.php");
?>
求解答php简单计算器代码
朋友,你这段代码其实问题很多:
手误:switch($_POST['Submint'])
逻辑错误: if($_POST['txt_num1']!=null&&$_POST['txt_num2']!=null)
因为在没有提交的情况下,变量:$_POST['txt_num1']和$_POST['txt_num2']是不存在的
想法错误:
switch($_POST['Submint'])
{
case"+":$num3=$num1+$num2;break;
case"-":$num3=$num1-$num2;break;
case"*":$num3=$num1*$num2;break;
case"/":$num3=$num1/$num2;break;
default:break;
}
原因:你可以打印出变量看看:print_r($_POST)就知道问题所在了
4.考虑不周:<input type="text"name="txt_num3" value="<?php echo$num3php?>"/>在没有提交的情况下,你怎么来的变量:$num3php,即使有,也是$num3
方法:可以结合jquery来判断用户单击的是哪个submit,然后再提交给php来出来并返回结果。具体细节您自己学习吧,凭你现在写出来的代码,你还需要一步一步来。
END,本文到此结束,如果可以帮助到大家,还望关注本站哦!