Foro de elhacker.net

Programación => PHP => Mensaje iniciado por: Jarcx9 en 25 Noviembre 2014, 16:08 pm



Título: No me muestra resultados Paginador PHP,MYSQL
Publicado por: Jarcx9 en 25 Noviembre 2014, 16:08 pm
Estoy implementando este sencillo  paginador, me funciono bn pero cuando trate de hacerlo con PDO no me muestra los valores pero si muestra cuantos resultados se trajeron, estoy probando pero no me funciona, espero me puedan colaborar

Gracias :cool:

Código
  1. <html>
  2. <head>
  3. <title>ShotDev.Com Tutorial</title>
  4. </head>
  5. <body>
  6. <?php
  7. $db_username = "";
  8. $db_password = "";
  9. $db = "oci:dbname=";
  10. //$conn = new PDO($db,$db_username,$db_password);
  11.  
  12. try{
  13.    $conn = new PDO($db,$db_username,$db_password);
  14.    echo "conectado correctamente";
  15. }catch(PDOException $e){
  16.    echo ($e->getMessage());
  17.    echo "<br>Error Conection";
  18. }
  19.    $st=$conn->prepare("SELECT PD_ID, PD_CANTIDAD, PRODUCTOS_PRO_ID, DEVOLUCION_MM_DMM_ID FROM PRODUCTO_DEVOLUCION ORDER BY PD_ID ASC");
  20.    $st->execute( );
  21.    $Result=$st->fetchAll($Result);
  22.  
  23.     foreach ($Result as $Result1) :
  24.       $a=$Result1['PD_ID'];          
  25.     endforeach;
  26.  
  27.    $Num_Rows=$Result;
  28.  
  29.    $Num_Rows=count($Num_Rows);
  30.  
  31.  
  32.  
  33.  
  34. $Per_Page = 2;   // Per Page
  35.  
  36. $Page = $_GET["Page"];
  37. if(!$_GET["Page"])
  38. {
  39. $Page=1;
  40. }
  41.  
  42. $Prev_Page = $Page-1;
  43. $Next_Page = $Page+1;
  44.  
  45. $Page_Start = (($Per_Page*$Page)-$Per_Page);
  46. if($Num_Rows<=$Per_Page)
  47. {
  48. $Num_Pages =1;
  49. }
  50. else if(($Num_Rows % $Per_Page)==0)
  51. {
  52. $Num_Pages =($Num_Rows/$Per_Page) ;
  53. }
  54. else
  55. {
  56. $Num_Pages =($Num_Rows/$Per_Page)+1;
  57. $Num_Pages = (int)$Num_Pages;
  58. }
  59. $Page_End = $Per_Page * $Page;
  60. if ($Page_End > $Num_Rows)
  61. {
  62. $Page_End = $Num_Rows;
  63. }
  64.  
  65. ?>
  66. <table width="600" border="1">
  67.  <tr>
  68.    <th width="91"> <div align="center">CustomerID </div></th>
  69.    <th width="98"> <div align="center">Name </div></th>
  70.    <th width="198"> <div align="center">Email </div></th>
  71.    <th width="97"> <div align="center">CountryCode </div></th>
  72.  
  73.  </tr>
  74. <?php
  75. for($i=$Page_Start;$i<$Page_End;$i++)
  76. {
  77. ?>
  78.  <tr>
  79.    <td><div align="center"><?php echo $Result["PD_ID"][$i];?></div></td>
  80.    <td><?php echo $Result["PD_CANTIDAD"][$i];?></td>
  81.    <td><?php echo $Result["PRODUCTOS_PRO_ID"][$i];?></td>
  82.    <td><div align="center"><?php echo $Result["DEVOLUCION_MM_DMM_ID"][$i];?></div></td>
  83.  
  84.  </tr>
  85. <?php
  86. }
  87. ?>
  88. </table>
  89.  
  90. <br>
  91. Total <?php $Num_Rows;?> Record : <?php $Num_Pages;?> Page :
  92. <?php
  93. if($Prev_Page)
  94. {
  95. echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page'><< Back</a> ";
  96. }
  97.  
  98. for($i=1; $i<=$Num_Pages; $i++){
  99. if($i != $Page)
  100. {
  101. echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i'>$i</a> ]";
  102. }
  103. else
  104. {
  105. echo "<b> $i </b>";
  106. }
  107. }
  108. if($Page!=$Num_Pages)
  109. {
  110. echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page'>Next>></a> ";
  111. }
  112. //oci_close($objConnect);
  113. ?>
  114. </body>
  115. </html>
  116.  



De esta forma si me funciona pero como dije quisiera hacerlo en PDO

Código
  1.  
  2.     $dbhost = "localhost:1521/xe";
  3.   //  static public $mvc_bd_nombre   = "prueba_ccl";
  4.     $dbuser  = "HR";
  5.     $dbpass    = "1234";
  6.  
  7. $objConnect = oci_connect($dbuser,$dbpass,$dbhost);
  8. $strSQL = "SELECT PD_ID, PD_CANTIDAD, PRODUCTOS_PRO_ID, DEVOLUCION_MM_DMM_ID FROM PRODUCTO_DEVOLUCION ORDER BY PD_ID ASC";
  9. $objParse = oci_parse ($objConnect, $strSQL);
  10. oci_execute ($objParse,OCI_DEFAULT);
  11.  
  12. $Num_Rows = oci_fetch_all($objParse, $Result);
  13.  
  14.  


Título: Re: No me muestra resultados Paginador PHP,MYSQL
Publicado por: Jarcx9 en 2 Diciembre 2014, 14:26 pm
No he vuelto a tocar este tema pues he estado ocupado con otras cosistas, pero si me urge saber como podria hacerlo,

Les Agradeceria mucho su colaboracion!