<%@ page import="java.sql.*" %>
<%@ page import="com.mysql.jdbc.Driver" %>
<%@ page import="java.util.Date" %><%
Connection conn = null;
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://10.222.1.104:3306/discuz", "root", "passw0rd");
} catch (SQLException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
String sql = "select t.* from (select * from cdb_posts ORDER by dateline desc ) t limit 5";
Statement stmt = null;
ResultSet rs = null;
try {
stmt= conn.createStatement();
rs = stmt.executeQuery(sql);
} catch (SQLException e) {
e.printStackTrace();
}%>
<% if(rs!=null){
while(rs.next()){
%>
<tr vAlign=top style="cursor:hand" onclick="showDetail(this, '', '');">
<td height=10 width="10" align="right" valign="bottom">
<image width="10" height="10" src="/images/arrow.gif" />
</td>
<td height=10 align="left" valign="bottom" class="gray-dashed">
<font style="font-size:12px;color:#353535">
<%=rs.getString("subject") %>
</font>
</td>
<td height=10 align="right" valign="bottom" class="gray-dashed">
<font style="font-size:12px;color:#353535">
<% Date d = new Date(rs.getTimestamp("dateline").getTime()) ; %>
[<%= d %>
</font>]
</td>
<td width="5"> </td>
</tr>
<%
}
rs.close();
}
%>项目需要把这个jsp翻译成 php 有高手么?
<%@ page import="com.mysql.jdbc.Driver" %>
<%@ page import="java.util.Date" %><%
Connection conn = null;
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://10.222.1.104:3306/discuz", "root", "passw0rd");
} catch (SQLException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
String sql = "select t.* from (select * from cdb_posts ORDER by dateline desc ) t limit 5";
Statement stmt = null;
ResultSet rs = null;
try {
stmt= conn.createStatement();
rs = stmt.executeQuery(sql);
} catch (SQLException e) {
e.printStackTrace();
}%>
<% if(rs!=null){
while(rs.next()){
%>
<tr vAlign=top style="cursor:hand" onclick="showDetail(this, '', '');">
<td height=10 width="10" align="right" valign="bottom">
<image width="10" height="10" src="/images/arrow.gif" />
</td>
<td height=10 align="left" valign="bottom" class="gray-dashed">
<font style="font-size:12px;color:#353535">
<%=rs.getString("subject") %>
</font>
</td>
<td height=10 align="right" valign="bottom" class="gray-dashed">
<font style="font-size:12px;color:#353535">
<% Date d = new Date(rs.getTimestamp("dateline").getTime()) ; %>
[<%= d %>
</font>]
</td>
<td width="5"> </td>
</tr>
<%
}
rs.close();
}
%>项目需要把这个jsp翻译成 php 有高手么?
<?php
//创建数据库连接
$conn = mysql_connect("10.222.1.104:3306", "root", "passw0rd") or die("连接数据库错误").mysql_error();
//选择数据库
mysql_select_db("discuz",$conn);
//选择相对应该的字符编码
mysql_query("set names encoding");//encoding = 字符编码
$sql = " select t.* from (select * from cdb_posts ORDER by dateline desc ) t limit 5 ";
//得到查询结果
$result = mysql_query($sql);while ($row = mysql_fetch_array($result,MYSQL_ASSOC)){ //把每行数据保存至数据$row
?>
<tr vAlign=top style="cursor:hand" onclick="showDetail(this, '', '');">
<td height=10 width="10" align="right" valign="bottom">
<image width="10" height="10" src="/images/arrow.gif" />
</td>
<td height=10 align="left" valign="bottom" class="gray-dashed">
<font style="font-size:12px;color:#353535">
<? echo $row["subject"]; ?>
</font>
</td>
<td height=10 align="right" valign="bottom" class="gray-dashed">
<font style="font-size:12px;color:#353535">
[<? echo strtotime($row['dateline'];) //取得日期的UNIX时间==java getTime() ?>]
</font>
</td>
<td width="5"> </td>
</tr>
<?
}
//关闭数据库连接
mysql_close($conn);
?>
顺手写的,没有经过测试,不过应该差不多,希望能给你提供帮助.
<?php
$conn = mysql_connect("localhost","root","passw0rd");
mysql_select_db("数据库名");
mysql_query("set names utf8;",$conn);
$sql = "select t.* from (select * from cdb_posts ORDER by dateline desc ) t limit 5";
$rs = mysql_query($sql);
?>
<?php if(@mysql_num_rows($rs)>0){
while ($row = mysql_fetch_array($rs, MYSQL_ASSOC)) { ?>
<tr vAlign=top style="cursor:hand" onclick="showDetail(this, '', '');">
<td height=10 width="10" align="right" valign="bottom">
<image width="10" height="10" src="/images/arrow.gif" />
</td>
<td height=10 align="left" valign="bottom" class="gray-dashed">
<font style="font-size:12px;color:#353535">
<?php echo $row['subject'] ?>
</font>
</td>
<td height=10 align="right" valign="bottom" class="gray-dashed">
<font style="font-size:12px;color:#353535">
<? $d=date('Y-m-d',$row['dateline']); ?>
[<?echo $d; ?>
</font>]
</td>
<td width="5"> </td>
</tr>
<?php
}
mysql_close($conn);
}
?>大概就这样
在php中
* include()与include_once()* require()与require_once()
函数是用来引入的
具体lz可以google or baidu
</iframe>这样就行了!
上面的方法不错
//php中可以这样嵌套页面
require_once('http://10.222.1.104:8080/discuz/foruminfo.php');
<style type="text/css">
.gray-dashed {
border-bottom: #000 1px dashed;
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
color: #3c3c3c;
LINE-HEIGHT: 16px
}
.list {
LINE-HEIGHT: 16px
}
</style>
没效果是不是CSS冲突了?
$employee_no = $_GET['employeeid'];
$employee_name = $_GET['username_erp'];
?>
<script type="text/javascript">
function showDetail_erpforum(tid){
var url = "http://10.222.1.104:8080/discuz/erp_sso.php?employeeid="+$employee_no+"&username_erp="+$employee_name"&tid="+tid ;
window.open(url);
}
</script>
这样的js 有问题,真的不知道这里的 php变量该怎么拼接到url上去还有这个调用是不是也不对呢?
<tr vAlign=top style="cursor:hand" onclick="showDetail_erpforum(<?php $row['tid'] ?>);">