Trouble Handling Data from PDO Query

Discussion in 'PHP' started by scottlpool2003, Mar 14, 2013.

  1. #1
    I've been working on a new pagination script and have encountered another problem.

    Bare in mind, I'm working on MSSQL not MySQL.

    The script is semi converted from a script using the old type mssql_query and I'm trying to get it all working nicely in PDO.

    So, when handling the data in the old script, I'd use:
    <?=mssql_result($objQuery,$i,"id");?>
    PHP:
    Which is built using:
    $objQuery = mssql_query($strSQL) or die ("Error Query [".$strSQL."]");
    $Num_Rows = mssql_num_rows($objQuery);
    PHP:
    With PDO not being able to handle num_rows, I did a little research and found:
    $sth->fetch(PDO::FETCH_NUM);
    PHP:
    So I guess, the question is how do I convert:
    <?php echo mssql_result($objQuery,$i,"title");?>
    PHP:
    to work using PDO and:
    
     
    $Page_Start = (($Per_Page*$Page)-$Per_Page);
    if($Num_Rows<=$Per_Page)
    {
       $Num_Pages =1;
    }
    else if(($Num_Rows % $Per_Page)==0)
    {
       $Num_Pages =($Num_Rows/$Per_Page) ;
    }
    else
    {
       $Num_Pages =($Num_Rows/$Per_Page)+1;
       $Num_Pages = (int)$Num_Pages;
    }
     
    //Determine where the page will end
     
    $Page_End = $Per_Page * $Page;
    IF ($Page_End > $Num_Rows)
    {
       $Page_End = $Num_Rows;
    }
     
    ?>
    
    PHP:
     
    scottlpool2003, Mar 14, 2013 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    create a seperate function that does the job for you!
     
    EricBruggema, Mar 15, 2013 IP