<%@ 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">&nbsp;
    <image width="10" height="10" src="/images/arrow.gif" />&nbsp;
  </td>
  <td height=10 align="left" valign="bottom" class="gray-dashed">
<font style="font-size:12px;color:#353535"> &nbsp;&nbsp;
  <%=rs.getString("subject") %>
    </font>
  </td>
  <td height=10 align="right" valign="bottom" class="gray-dashed">&nbsp;
<font style="font-size:12px;color:#353535">
<% Date d = new Date(rs.getTimestamp("dateline").getTime()) ; %>
   [<%= d %>
</font>]
  </td>
  <td width="5">&nbsp;</td>
</tr>
<%
}
rs.close();
}
%>项目需要把这个jsp翻译成 php 有高手么?

解决方案 »

  1.   

    数据库增删改查的操作建议从ECSHOP等开源的软件中直接把DAO类copy过来稍做修改就OK了,例如ECSHOP中的cls_mysql.php
      

  2.   


    <?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">&nbsp;
    <image width="10" height="10" src="/images/arrow.gif" />&nbsp;
    </td>
    <td height=10 align="left" valign="bottom" class="gray-dashed">
    <font style="font-size:12px;color:#353535"> &nbsp;&nbsp;
      <? echo $row["subject"]; ?>
    </font>
    </td>
    <td height=10 align="right" valign="bottom" class="gray-dashed">&nbsp;
    <font style="font-size:12px;color:#353535">
    [<? echo strtotime($row['dateline'];) //取得日期的UNIX时间==java getTime() ?>]
    </font>
    </td>
    <td width="5">&nbsp;</td>
    </tr>
    <?
    }
    //关闭数据库连接
    mysql_close($conn);
    ?>
    顺手写的,没有经过测试,不过应该差不多,希望能给你提供帮助.
      

  3.   


    <?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">&nbsp;
                <image    width="10" height="10" src="/images/arrow.gif" />&nbsp;
              </td>
              <td height=10 align="left" valign="bottom" class="gray-dashed">
                <font style="font-size:12px;color:#353535"> &nbsp;&nbsp;
                  <?php echo $row['subject'] ?>
                </font>
              </td>
              <td height=10 align="right" valign="bottom" class="gray-dashed">&nbsp;
                <font style="font-size:12px;color:#353535"> 
    <? $d=date('Y-m-d',$row['dateline']); ?>          
                   [<?echo $d; ?>
                </font>]
              </td>
              <td width="5">&nbsp;</td>
            </tr>
        <?php
            }
            mysql_close($conn);
        }
        ?>大概就这样
      

  4.   

    php 不需要像java那样引用一些类么?
      

  5.   

    哈哈   看你的需求了  当然也有引如的时候  
    在php中
    * include()与include_once()* require()与require_once()
    函数是用来引入的
    具体lz可以google  or baidu
      

  6.   

    ttttttttttt
      

  7.   

    我现在又有一个问题啊 在一个系统的jsp中文件中想要 inclede 那个 php  这该怎么写啊?
      

  8.   

    <iframe border="0" id="foruminfo" src="http://10.222.1.104:8080/discuz/foruminfo.php" >
    </iframe>这样就行了!
      

  9.   

    jsp页面中嵌入php页面呀。
    上面的方法不错
      

  10.   


    //php中可以这样嵌套页面
    require_once('http://10.222.1.104:8080/discuz/foruminfo.php');
      

  11.   

    在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>
      

  12.   

    就是这样的。
    没效果是不是CSS冲突了?
      

  13.   

    <?php
    $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'] ?>);">