如何通过PHP打印长文本?

时间:2013-08-03 10:18:51

标签: php mysql web-applications mysqli

右键我正面临打印长文本的问题。在我的数据库中,我有长文本格式的数据,该字段有大约2000行文本,所以我怎么能打印出来。

我在这里给我的文件的完整代码,请仔细检查并尝试解决我的问题

<?php
if($objConnect = mysql_connect("localhost","root","")){
$objDB = mysql_select_db("android");
    $from_date=$_GET['from_date'];
    $to_date=$_GET['to_date'];
    $time = strtotime($from_date);
    $time1 = strtotime($to_date);
    $fdate = date( 'Y-m-d', $time );
    $todate = date( 'Y-m-d', $time1 );
    $tmpdate="";
    $time2 = strtotime($tmpdate);
    $tempdate = date( 'Y-m-d', $time2 );
    if($fdate==$tempdate){
    echo "if block";
        $strSQL = "SELECT LessonText FROM lesson_details ";/*Here this field LessonText is Long Text*/
        $objQuery = mysql_query($strSQL);
        $intNumField = mysql_num_fields($objQuery);
        $resultArray = array();
        while($obResult = mysql_fetch_array($objQuery)){
            $arrCol = array();
            for($i=0;$i<$intNumField;$i++){
                $arrCol[mysql_field_name($objQuery,$i)] = $obResult[$i];
            }
        array_push($resultArray,$arrCol);
        }
        $Jdata=(json_encode(array('lessons:'=>$resultArray)));
        if($Jdata!=""){
            $error_code=0;
            $error_massage="Success";
            $Result=array(array('Lesson_details:'=>$resultArray),array('error_code:'=>$error_code,'error_massage:'=>$error_massage));
            echo json_encode($Result);
        }
        else{
            echo "Else Block";
            $error_code=1;
            $error_massage="No Record Found";
            $Result=array(array('Lesson_details:'=>$resultArray),array('error_code:'=>$error_code),array('error_massage:'=>$error_massage));
            echo json_encode($Result);
        }               
    }
    elseif($fdate!="1970-01-01" && $todate!="1970-01-01"){
        $strSQL = "SELECT * FROM lesson_details WHERE UpdatedDate>='$fdate' &&UpdatedDate<='$todate'";
        $objQuery = mysql_query($strSQL);
        $intNumField = mysql_num_fields($objQuery);
        $resultArray = array();
        while($obResult = mysql_fetch_array($objQuery)){
            $arrCol = array();
            for($i=0;$i<$intNumField;$i++){
                $arrCol[mysql_field_name($objQuery,$i)] = $obResult[$i];
            }
            array_push($resultArray,$arrCol);
        }
        $Jdata=(json_encode(array('lessons:'=>$resultArray)));
        if($Jdata!=""){
            $error_code=0;
            $error_massage="Success";
            $Result=array(array('Lesson_details:'=>$resultArray),array('error_code:'=>$error_code,'error_massage:'=>$error_massage));
            echo json_encode($Result);
        }
        else{
            echo "Else Block";
            $error_code=1;
            $error_massage="No Record Found";
            $Result=array(array('Lesson_details:'=>$resultArray),array('error_code:'=>$error_code),array('error_massage:'=>$error_massage));
            echo json_encode($Result);
        }       
    }
    else{
        $strSQL = "SELECT * FROM lesson_details WHERE UpdatedDate>='$fdate'";
        $objQuery = mysql_query($strSQL);
        $intNumField = mysql_num_fields($objQuery);
        $resultArray = array();
        while($obResult = mysql_fetch_array($objQuery)){
            $arrCol = array();
            for($i=0;$i<$intNumField;$i++){
                $arrCol[mysql_field_name($objQuery,$i)] = $obResult[$i];
            }
            array_push($resultArray,$arrCol);
        }
        $Jdata=json_encode($resultArray);
        $Jdata=(json_encode(array('lessons:'=>$resultArray)));
        if($Jdata!=""){
            $error_code=0;
            $error_massage="Success";
            $Result=array(array('Lesson_details:'=>$resultArray),array('error_code:'=>$error_code,'error_massage:'=>$error_massage));
            echo json_encode($Result);
        }
        else{
            echo "Else Block";
            $error_code=1;
            $error_massage="No Record Found";
            $Result=array(array('Lesson_details:'=>$resultArray),array('error_code:'=>$error_code),array('error_massage:'=>$error_massage));
            echo json_encode($Result);
        }       
    }
}
else{
    $error=array("ErrCode"=>2,"ErrMsg"=>"Database connection error");
    echo (json_encode($error));
}
?>

2 个答案:

答案 0 :(得分:0)

我找到了解决方案,所以我在这里分享 在我的情况下,这是utf8编码的问题。所以我在我的选择查询下面添加了以下行 mysql_query('SET CHARACTER SET utf8')

答案 1 :(得分:-1)

这样的事情,我相信:

print $longtext;