- 论坛徽章:
- 0
|
为什么,我用下面的这个例子取不出row[0]的值呀?
还有,我用odbc_field_name($rst,$q)这个方法也取不出它的field_name呢?
------------------------------------------------------------------
$page = $arr_request["page"];
$sql_type="exec p_comm_get_id_from_dict @main=\"理财博览\"";
$conn = odbc_connect($odbc_name, $odbc_uid,$odbc_pwd) or die ("连接ODBC失败" ;
$rst=odbc_exec($conn,$sql_type);
$type=odbc_result($rst,1);
odbc_free_result($rst);
//$type=204;
$sql = "select id,title,time from t_grlc_news where (datediff(d,time,getdate())<30) and type=$type order by time DESC";
$record_num = "select count(*) as record_number from t_grlc_news where datediff(d,time,getdate())<30 and type=$type";
//定义每页记录数
$pagesize =16;
//连接数据库求出总页数
//$conn = odbc_connect($odbc_name, $odbc_uid,$odbc_pwd) or die ("连接ODBC失败" ;
$rst = odbc_exec($conn,$record_num) or die("查询出错" ; //执行取得记录总数SQL语句
$record_count_num = odbc_result($rst,"record_number" ; //取得记录总数,在这里也可以用$recordcount = odbc_result($rst,"record_number" ;
odbc_free_result($rst); //释放资源
$page_count_num = ceil($record_count_num/$pagesize);
//控制接收页数值的正确性
if($page>;$page_count_num)
{
$page = $page_count_num;
}elseif($page<1)
{
$page = 1;
}
//以下输出内容
$rst = odbc_exec($conn,$sql) or die("$sql查询出错" ; //执行取得数据SQL语句
$fieldcount = odbc_num_fields($rst); //取得字段总数
print "<table width=90% border="0" cellspacing="0" cellpadding="4" align=center>;";
$rowi = ($page-1)*$pagesize+1;
for($i=0;$i<$pagesize;$i++){
print "<tr>;";
if($rowi<=$record_count_num){
odbc_fetch_into($rst,$rowi,&$row);
if($i==0) print "<center>;<img src=\"../../images/grlc/e1.gif\" width=\"526\" height=\"36\">;<br>;<hr width=100% color=#003399>;";
for($q=1;$q<=$fieldcount;$q++)
{
if(odbc_field_name($rst,$q)=="id"
{
$news_id=$row[0];
}
if (odbc_field_name($rst,$q)=="title"
{
print "<td width=80%>;  <img src=\"../../images/grlc/star.gif\" width=\"8\" height=\"8\">; <a href="lcbl_detail.php?id=$news_id" target=_blank>;" . $row[1] . "</td>;";
}
if(odbc_field_name($rst,$q)=="time"
{
print "<td width=20%>;" .substr($row[2],0,10) . "</td>;";
}
}
$rowi = $rowi+1;
}
print "</tr>;";
}
print "</table>;";
odbc_free_result($rst); //释放资源
odbc_close($conn); //关闭连接并释放资源
if ($page_count_num>;1)
{
print "<form method=post action=\"$PHP_SELF?page=$pages\">;";
print "<table border=0 cellspacing=\"0\" cellpadding=\"0\">;<tr bgcolor="#ffffff">;";
if($page>;1)
{ //页码比0大,表示有数据
print "<td width=80>;<a href=\"$PHP_SELF?page=1\">;首页</td>;";
}
else{
print "<td width=80>;首页</td>;";
}
if($page>;1){
$pages = $page - 1;
print "<td width=80>;<a href=\"$PHP_SELF?page=$pages$sql_condition\">;上页</td>;";
}
else{
print "<td width=80>;上页</td>;";
}
if($page<$page_count_num){
$pages = $page + 1;
print "<td width=80>;<a href=\"$PHP_SELF?page=$pages$sql_condition\">;下页</td>;";}
else{
print "<td width=80>;下页</td>;";
}
if($page<$page_count_num){
print "<td width=80>;<a href=\"$PHP_SELF?page=$page_count_num\">;尾页</td>;";
}
else{
print "<td width=80>;尾页</td>;";
}
print "<td width=80>;页码($page/$page_count_num)</td>;";
print "<td width=80 align = center>;<input type=input size=3 name=page>; <input type=submit value=go name=go>;</td>;";
print "</tr>;";
print "</table>;";
print "</form>;";
} |
|