|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
在学习HTML中我想边学边做是最有效的方式,当然这一方式对于学习PHP同样是最有效的。 PHP上传图片并分页显示,以下代码:
- <?php $id=mysql_connect('localhost','root','root'); mysql_select_db("db_database12",$id); mysql_query("set names gb2312"); ?>
复制代码 index.php:
- <?php session_start(); include "conn.php"; if ($page=="") {$page=1;}; ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>上传多图片到办事
器并分页显示 - www.cxybl.com</title> <style type="text/CSS"> <!-- .style1 {font-size: 12px} --> </style> </head> <body> <table width="450" height="259" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="134" height="68"> </td> <td width="204"> </td> <td width="104"> </td> </tr> <form action="index_ok.php" method="post" enctype="multipart/form-data" name="form1"> <tr> <td height="30"> </td> <td><input name="file[]" type="file" size="18"></td> <td> </td> </tr> <tr> <td height="30"> </td> <td><input name="file[]" type="file" size="18"></td> <td> </td> </tr> <tr> <td height="30"> </td> <td><input name="file[]" type="file" size="18"></td> <td> </td> </tr> <tr> <td height="42"> </td> <td align="center"><input name="Submit" type="submit" id="Submit" value="提交"></td> <td> </td> </tr> </form> <tr> <td height="60"> </td> <td> </td> <td> </td> </tr> </table> <table width="450" border="0" cellspacing="0" cellpadding="0"> <?php if ($page){ $page_size=4; $query="select count(*) as total from tb_image2 where id"; $result=mysql_query($query); $message_count=@mysql_result($result,0,"total"); $page_count=ceil($message_count/$page_size); $offset=($page-1)*$page_size; for ($i=1; $i<=2; $i++) { echo "<tr>"; ?> <?php if ($i==1) { $query="select * from tb_image2 where id order by data desc limit $offset, $page_size"; $result=mysql_query($query);} $j=1; while ($myrow=mysql_fetch_array($result)){ if ($j<=2){ ?> <td height="150" colspan="2" align="center" valign="middle"> <table width="225" height="150" border="0" cellspacing="0"> <tr align="center" valign="middle"> <td width="225" height="125" align="center" valign="middle"> <?php echo "<img src=\"$myrow[path]\" width=\"224\" height=\"120\">"?></td> </tr> <tr align="left" valign="top"> <td height="25" align="center" valign="middle"> <span class="style1"><?php echo $myrow[data];?></span> </td> </tr> </table></td> <?php } ++$j; if ($j==3){ break; }} echo "</tr>"; } ?> </table> <table width="450" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="50%" class="style1"> 页次:<?php echo $page;?> / <?php echo $page_count;?> 页 纪录
:<?php echo $message_count;?> 条 </td> <td width="39%" class="style1"> 分页: <?php $xsoudh="id=$id"; $next=$ljjl*10; $n=$ljjl-1; $m=$ljjl+1; $prev_page=$page-10; if ($ljjl==0){ echo ""; }else{ echo "<a href='$PATH_INFO?vv=0&ljjl=0&page=1&$xsoudh'>首页</a> "; $ccc=$vv-10; echo "<a href='$PATH_INFO?vv=$ccc&ljjl=$n&page=$prev_page&$xsoudh'>上十页</a>"; }?> <?php for ($j=1;$j<=$page_count;$j++) { $pnext=$next+$j; if ($mm==10){ break; } if ($mm>$page_count){ break;} if ($page_count-$vv<10){ if ($mm>=$page_count-$vv){break;} } ?> <?php echo "<a href='$PATH_INFO?vv=$vv&ljjl=$ljjl&page=$pnext&$xsoudh'> $pnext </a>"; $mm=$mm+1; } ?> </td> <td width="11%" class="style1"> <?php $vv=$vv+$mm; if ($page_count-$vv<=0){ echo ""; }else{ echo "<a href='$PATH_INFO?vv=$vv&ljjl=$m&page=$pnext&$xsoudh'>下十页</a>"; } if ($message_count==0){ echo "没有纪录
!";} }?> </td> </tr> </table> </body> </html>
复制代码 index_ok.php:
- <?php session_start(); include "conn.php"; ?> <?php if($_POST["Submit"]!=""){ if(!is_dir("./upfile")){ mkdir("./upfile");} for($i=0;$i<count($file);$i++){ $path="upfile/".date("Ymdhis").$_FILES["file"]["name"][$i]; move_uploaded_file($_FILES["file"]["tmp_name"][$i],$path); $data=date("Y-m-d H:m:s"); $query="insert into tb_image2 (path,data) values ('$path','$data')"; //创立
拔出
图片数据的sql语句 $result=mysql_query($query);} echo "图片上传胜利
,请稍等..."; echo "<meta http-equiv=\"refresh\" content=\"3; url=index.php\">";} ?>
复制代码 接触MYSQL,开始设计数据库程序 |
|