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 "
<html>
<head>
<title>Maintenance Stock</title>
</head>
<body>
<?php
ini_set('display_errors', 1);
error_reporting(~0);
$strKeyword = null;
if(isset($_POST["txtKeyword"]))
{
$strKeyword = $_POST["txtKeyword"];
}
if(isset($_GET["txtKeyword"]))
{
$strKeyword = $_GET["txtKeyword"];
}
?>
<form name="frmSearch" method="post" action="<?php echo $_SERVER['SCRIPT_NAME'];?>">
<table width="599" border="1">
<tr>
<th>Keyword
<input name="txtKeyword" type="text" id="txtKeyword" value="<?php echo $strKeyword;?>">
<input type="submit" value="Search"></th>
</tr>
</table>
</form>
<?php
$serverName = "localhost";
$userName = "sa";
$userPassword = "password";
$dbName = "hpm";
$connectionInfo = array("Database"=>$dbName, "UID"=>$userName, "PWD"=>$userPassword, "MultipleActiveResultSets"=>true);
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn === false ) {
die( print_r( sqlsrv_errors(), true));
}
$stmt = "SELECT * FROM mdk_datakendaraan WHERE norangka LIKE '%".$strKeyword."%' ";
$params = array();
$options = array( "Scrollable" => SQLSRV_CURSOR_KEYSET );
$query = sqlsrv_query( $conn, $stmt , $params, $options );
$num_rows = sqlsrv_num_rows($query);
$per_page = 20; // Per Page
$page = 1;
if(isset($_GET["Page"]))
{
$page = $_GET["Page"];
}
$prev_page = $page-1;
$next_page = $page+1;
$row_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;
}
$row_end = $per_page * $page;
if($row_end > $num_rows)
{
$row_end = $num_rows;
}
$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";
?>
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">Kode Tipe </div></th>
<th width="98"> <div align="center">Nama </div></th>
<th width="198"> <div align="center">No. Rangka </div></th>
<th width="97"> <div align="center">No. Mesin </div></th>
<th width="59"> <div align="center">Nama Sales </div></th>
<th width="71"> <div align="center">Nama Running </div></th>
</tr>
<?php
while($row = sqlsrv_fetch_array($stmt2))
{
?>
<tr>
<td><div align="center"><?php echo $row["kode_tipe"];?></div></td>
<td><?php echo $row["nama"];?></td>
<td><?php echo $row["norangka"];?></td>
<td><div align="center"><?php echo $row["nomesin"];?></div></td>
<td align="right"><?php echo $row["nama_sales_mdk"];?></td>
<td align="right"><?php echo $row["nama_cust_mdk"];?></td>
</tr>
<?php
}
?>
</table>
<br>
Total <?php echo $num_rows;?> Record : <?php echo $num_pages;?> Page :
<?php
if($prev_page)
{
echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$prev_page&txtKeyword=$strKeyword'><< Back</a> ";
}
for($i=1; $i<=$num_pages; $i++){
if($i != $page)
{
echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i&txtKeyword=$strKeyword'>$i</a> ]";
}
else
{
echo "<b> $i </b>";
}
}
if($page!=$num_pages)
{
echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$next_page&txtKeyword=$strKeyword'>Next>></a> ";
}
sqlsrv_close($conn);
?>
</body>
</html>