Mohon dibantu, saya meiliki script seperti dibawah ini. namun setelah di running index.php nya.
muncul error seperti ini. Mohon bisa dibetulkan kesalahan saya dimana?
" Warning: sqlsrv_fetch_array() expects parameter 1 to be resource, string given in D :\xampp\htdocs\testing2\index.php on line 98 "
  1. <html>
  2. <head>
  3. <title>Maintenance Stock</title>
  4. </head>
  5. <body>
  6. <?php
  7. ini_set('display_errors', 1);
  8. error_reporting(~0);
  9.  
  10. $strKeyword = null;
  11.  
  12. if(isset($_POST["txtKeyword"]))
  13. {
  14. $strKeyword = $_POST["txtKeyword"];
  15. }
  16. if(isset($_GET["txtKeyword"]))
  17. {
  18. $strKeyword = $_GET["txtKeyword"];
  19. }
  20. ?>
  21. <form name="frmSearch" method="post" action="<?php echo $_SERVER['SCRIPT_NAME'];?>">
  22. <table width="599" border="1">
  23. <tr>
  24. <th>Keyword
  25. <input name="txtKeyword" type="text" id="txtKeyword" value="<?php echo $strKeyword;?>">
  26. <input type="submit" value="Search"></th>
  27. </tr>
  28. </table>
  29. </form>
  30. <?php
  31. $serverName = "localhost";
  32. $userName = "sa";
  33. $userPassword = "password";
  34. $dbName = "hpm";
  35.  
  36. $connectionInfo = array("Database"=>$dbName, "UID"=>$userName, "PWD"=>$userPassword, "MultipleActiveResultSets"=>true);
  37.  
  38. $conn = sqlsrv_connect( $serverName, $connectionInfo);
  39.  
  40. if( $conn === false ) {
  41. die( print_r( sqlsrv_errors(), true));
  42. }
  43.  
  44. $stmt = "SELECT * FROM mdk_datakendaraan WHERE norangka LIKE '%".$strKeyword."%' ";
  45.  
  46. $params = array();
  47. $options = array( "Scrollable" => SQLSRV_CURSOR_KEYSET );
  48. $query = sqlsrv_query( $conn, $stmt , $params, $options );
  49.  
  50. $num_rows = sqlsrv_num_rows($query);
  51.  
  52. $per_page = 20; // Per Page
  53. $page = 1;
  54.  
  55. if(isset($_GET["Page"]))
  56. {
  57. $page = $_GET["Page"];
  58. }
  59.  
  60. $prev_page = $page-1;
  61. $next_page = $page+1;
  62.  
  63. $row_start = (($per_page*$page)-$per_page);
  64. if($num_rows<=$per_page)
  65. {
  66. $num_pages =1;
  67. }
  68. else if(($num_rows % $per_page)==0)
  69. {
  70. $num_pages =($num_rows/$per_page) ;
  71. }
  72. else
  73. {
  74. $num_pages =($num_rows/$per_page)+1;
  75. $num_pages = (int)$num_pages;
  76. }
  77. $row_end = $per_page * $page;
  78. if($row_end > $num_rows)
  79. {
  80. $row_end = $num_rows;
  81. }
  82.  
  83.  
  84. $stmt2 = " SELECT c.* FROM (SELECT ROW_NUMBER() OVER(ORDER BY norangka) AS RowID,* FROM mdk_datakendaraan WHERE norangka LIKE '%".$strKeyword."%') AS c WHERE c.RowID > $row_start AND c.RowID <= $row_end";
  85.  
  86.  
  87. ?>
  88. <table width="600" border="1">
  89. <tr>
  90. <th width="91"> <div align="center">Kode Tipe </div></th>
  91. <th width="98"> <div align="center">Nama </div></th>
  92. <th width="198"> <div align="center">No. Rangka </div></th>
  93. <th width="97"> <div align="center">No. Mesin </div></th>
  94. <th width="59"> <div align="center">Nama Sales </div></th>
  95. <th width="71"> <div align="center">Nama Running </div></th>
  96. </tr>
  97. <?php
  98. while($row = sqlsrv_fetch_array($stmt2))
  99.  
  100. {
  101. ?>
  102.  
  103. <tr>
  104. <td><div align="center"><?php echo $row["kode_tipe"];?></div></td>
  105. <td><?php echo $row["nama"];?></td>
  106. <td><?php echo $row["norangka"];?></td>
  107. <td><div align="center"><?php echo $row["nomesin"];?></div></td>
  108. <td align="right"><?php echo $row["nama_sales_mdk"];?></td>
  109. <td align="right"><?php echo $row["nama_cust_mdk"];?></td>
  110. </tr>
  111. <?php
  112. }
  113. ?>
  114. </table>
  115. <br>
  116. Total <?php echo $num_rows;?> Record : <?php echo $num_pages;?> Page :
  117. <?php
  118. if($prev_page)
  119. {
  120. echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$prev_page&txtKeyword=$strKeyword'><< Back</a> ";
  121. }
  122.  
  123. for($i=1; $i<=$num_pages; $i++){
  124. if($i != $page)
  125. {
  126. echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i&txtKeyword=$strKeyword'>$i</a> ]";
  127. }
  128. else
  129. {
  130. echo "<b> $i </b>";
  131. }
  132. }
  133. if($page!=$num_pages)
  134. {
  135. echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$next_page&txtKeyword=$strKeyword'>Next>></a> ";
  136. }
  137. sqlsrv_close($conn);
  138. ?>
  139. </body>
  140. </html>
  141.  
14890
Please login to answer!
/sangkep/answer/add-json/nogzip/1
/sangkep/answer/send-notification