|
|
|
ช่วยแก้ไขโค๊ดแสดง Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given |
|
|
|
|
|
|
|
ตรง mysql_query('...'); ก่อนปิด ; ใส่เพิ่ม or die(mysql_error());
แล้วก็เลิกใช้ mysql_ function ได้แล้วนะครับเขาประกาศให้เลิกใช้มานานมากมายมหาศาลแล้ว.
https://www.thaicreate.com/php/forum/095986.html
|
ประวัติการแก้ไข 2017-04-11 02:58:47
|
|
|
|
Date :
2017-04-11 02:57:31 |
By :
mr.v |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ถ้าอาจารย์ยังสอน mysql อยู่ ก็ไปหา apserv เวอร์ชั่นเก่าๆ น่าจะ 2.5.10 ที่ PHP 5.3 มาใช้กับ Code เก่าๆ
|
|
|
|
|
Date :
2017-04-11 08:54:35 |
By :
apisitp |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณคะจะนำไปปรับปรุงและแก้ไขคะ
|
|
|
|
|
Date :
2017-04-11 13:10:13 |
By :
Jsk |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date :
2017-04-11 14:55:10 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<?php
include("header.php");
include("config.php");
if ($_REQUEST[action] == "insert")
{
$sql = "SELECT * FROM group where groupid = '$_REQUEST[groupid]'";
$query = mysql_query($sql,$conn)or die(mysql_error());
$num_rows=mysql_num_rows($query);
if ($num_rows == 0)
{
$sql = "insert into group(groupid,groupname)
values ('$_REQUEST[groupid]','$_REQUEST[groupname]')";
mysql_query($sql,$conn)or die(mysql_error());
echo $sql;
header("Location: group.php");
}
else
{?>
<script language="javascript">
alert("ซ้ำค่ะ กรุณากรอกใหม่");
history.go(-1);
</script>
<?}
}
?>
<?php
if ($_REQUEST[action] == "delete")
{
$sql = "delete from group ";
$sql.= " where groupid='$_REQUEST[groupid]' ";
mysql_query($sql,$conn)or die (" error $sql; ");
header("Location: group.php");
}
?>
<div class="row"id="home">
<div class="col-sm-12 w3-xlarge">
<div class="panel panel-info">
<div class="panel-heading w3-xxlarge"><center>เพิ่มการใช้สิทธิ์</div>
<div class="panel-body w3-xlarge">
<form class="form-horizontal" method="post" action="group.php?action=insert" >
<div class="form-group">
<label class="control-label col-sm-3 " for="groupid">รหัสสิทธิ์</label>
<div class="col-sm-6">
<input type="text" class="form-control w3-xlarge" name="groupid" placeholder="ป้อนรหัสสิทธิ์" required>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="groupname">ชื่อสิทธิ์</label>
<div class="col-sm-6">
<input type="text" class="form-control w3-xlarge" name="groupname" placeholder="ป้อนชื่อสิทธิ์" required>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-6">
<button type="submit" class="btn btn-success w3-xlarge"> บันทึกข้อมูล</button>
<button type="reset" class="btn btn-danger w3-xlarge"> ยกเลิก</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<!-- แสดงข้อมูล-->
<div class="row">
<div class="col-sm-12 w3-xlarge">
<div class="panel panel-info">
<div class="panel-heading"><center></span> แสดงสิทธิ์การใช้</div>
<div class="panel-body">
<form class="navbar-form navbar-left" role="search" action="group.php">
<div class="form-group">
<div class="col-sm-2">
<select name="field" id="field" class="form-control w3-xlarge">
<option value="groupid">รหัสสิทธิ์</option>
</select>
</div>
</div>
<div class="form-group">
<div class="col-sm-3">
<input name="keyword" type="text" class="form-control w3-xlarge" placeholder="ข้อความ">
</div>
</div>
<div class="form-group">
<div class="col-sm-6">
<button type="submit" class="btn btn-primary w3-xlarge"> ค้นหาข้อมูล
</button>
</div>
</div>
</form>
</div>
<?php
$field=$_REQUEST["field"];
$keyword=$_REQUEST["keyword"];
if ($keyword == "")
{
$sql = "select * From group";
}
else
{
$sql = "select * From group";
$sql.= " where $field like '%$keyword%'";
}
$result = mysql_query($sql);
$Num_Rows = mysql_num_rows($result);
//
$Per_Page = 20;
$Page = $_GET["Page"];
if(!$_GET["Page"])
{
$Page=1;
}
$Prev_Page = $Page-1;
$Next_Page = $Page+1;
$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;
}
$sql .=" order by groupid asc LIMIT $Page_Start , $Per_Page";
$result = mysql_query($sql);
?>
<div class="table-responsive">
<table class="table table-hover">
<tr>
<td align="center">รหัสสิทธิ์</td>
<td>ชื่อสิทธิ์</td>
<td>จัดการข้อมูล</td>
</tr>
<?php
$i=0;
While($row= mysql_fetch_array($result)){
$groupid = $row["groupid"];
$groupname = $row["groupname"];
$i++;
?>
<tr>
<td align="center"><?php echo $groupid; ?></td>
<td><?php echo $groupname; ?></td>
<td>
<a class="btn btn-danger " href="group.php?action=delete&groupid=<?php echo $groupid; ?>" onclick="return confirm('ต้องการลบข้อมูลใช้หรือไม่ ')"> ลบ</A>
</td>
</tr>
<?php }?>
</table>
<?php echo $Num_Rows;?> รายการ : <?php echo $Num_Pages;?> Page :
<?php
if($Prev_Page)
{
echo " <a class='btn btn-success' href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page&groupname=$groupname&keyword=$keyword'><< Back</a> ";
}
for($i=1; $i<=$Num_Pages; $i++){
if($i != $Page)
{
echo " <a class='btn btn-success' href='$_SERVER[SCRIPT_NAME]?Page=$i&groupname=$groupname&keyword=$keyword'>$i</a> ";
}
else
{
echo "<b> $i </b>";
}
}
if($Page!=$Num_Pages)
{
echo " <a class='btn btn-success' href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page&groupname=$groupname&keyword=$keyword'>Next>></a> ";
}
mysql_close();
?>
</div>
</div>
</div>
</div>
</header>
<!-- จบแสดงข้อมูล -->
|
|
|
|
|
Date :
2017-12-26 14:57:09 |
By :
อรวรรณ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ช่วยแก้หน่อยค่ะ
Code (PHP)
<?php
include("header.php");
include("config.php");
if ($_REQUEST[action] == "insert")
{
$sql = "SELECT * FROM group where groupid = '$_REQUEST[groupid]'";
$query = mysql_query($sql,$conn)or die(mysql_error());
$num_rows=mysql_num_rows($query);
if ($num_rows == 0)
{
$sql = "insert into group(groupid,groupname)
values ('$_REQUEST[groupid]','$_REQUEST[groupname]')";
mysql_query($sql,$conn)or die(mysql_error());
echo $sql;
header("Location: group.php");
}
else
{?>
<script language="javascript">
alert("ซ้ำค่ะ กรุณากรอกใหม่");
history.go(-1);
</script>
<?}
}
?>
<?php
if ($_REQUEST[action] == "delete")
{
$sql = "delete from group ";
$sql.= " where groupid='$_REQUEST[groupid]' ";
mysql_query($sql,$conn)or die (" error $sql; ");
header("Location: group.php");
}
?>
<div class="row"id="home">
<div class="col-sm-12 w3-xlarge">
<div class="panel panel-info">
<div class="panel-heading w3-xxlarge"><center>เพิ่มการใช้สิทธิ์</div>
<div class="panel-body w3-xlarge">
<form class="form-horizontal" method="post" action="group.php?action=insert" >
<div class="form-group">
<label class="control-label col-sm-3 " for="groupid">รหัสสิทธิ์</label>
<div class="col-sm-6">
<input type="text" class="form-control w3-xlarge" name="groupid" placeholder="ป้อนรหัสสิทธิ์" required>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="groupname">ชื่อสิทธิ์</label>
<div class="col-sm-6">
<input type="text" class="form-control w3-xlarge" name="groupname" placeholder="ป้อนชื่อสิทธิ์" required>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-6">
<button type="submit" class="btn btn-success w3-xlarge"> บันทึกข้อมูล</button>
<button type="reset" class="btn btn-danger w3-xlarge"> ยกเลิก</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<!-- แสดงข้อมูล-->
<div class="row">
<div class="col-sm-12 w3-xlarge">
<div class="panel panel-info">
<div class="panel-heading"><center></span> แสดงสิทธิ์การใช้</div>
<div class="panel-body">
<form class="navbar-form navbar-left" role="search" action="group.php">
<div class="form-group">
<div class="col-sm-2">
<select name="field" id="field" class="form-control w3-xlarge">
<option value="groupid">รหัสสิทธิ์</option>
</select>
</div>
</div>
<div class="form-group">
<div class="col-sm-3">
<input name="keyword" type="text" class="form-control w3-xlarge" placeholder="ข้อความ">
</div>
</div>
<div class="form-group">
<div class="col-sm-6">
<button type="submit" class="btn btn-primary w3-xlarge"> ค้นหาข้อมูล
</button>
</div>
</div>
</form>
</div>
<?php
$field=$_REQUEST["field"];
$keyword=$_REQUEST["keyword"];
if ($keyword == "")
{
$sql = "select * From group";
}
else
{
$sql = "select * From group";
$sql.= " where $field like '%$keyword%'";
}
$result = mysql_query($sql);
$Num_Rows = mysql_num_rows($result);
//
$Per_Page = 20;
$Page = $_GET["Page"];
if(!$_GET["Page"])
{
$Page=1;
}
$Prev_Page = $Page-1;
$Next_Page = $Page+1;
$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;
}
$sql .=" order by groupid asc LIMIT $Page_Start , $Per_Page";
$result = mysql_query($sql);
?>
<div class="table-responsive">
<table class="table table-hover">
<tr>
<td align="center">รหัสสิทธิ์</td>
<td>ชื่อสิทธิ์</td>
<td>จัดการข้อมูล</td>
</tr>
<?php
$i=0;
While($row= mysql_fetch_array($result)){
$groupid = $row["groupid"];
$groupname = $row["groupname"];
$i++;
?>
<tr>
<td align="center"><?php echo $groupid; ?></td>
<td><?php echo $groupname; ?></td>
<td>
<a class="btn btn-danger " href="group.php?action=delete&groupid=<?php echo $groupid; ?>" onclick="return confirm('ต้องการลบข้อมูลใช้หรือไม่ ')"> ลบ</A>
</td>
</tr>
<?php }?>
</table>
<?php echo $Num_Rows;?> รายการ : <?php echo $Num_Pages;?> Page :
<?php
if($Prev_Page)
{
echo " <a class='btn btn-success' href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page&groupname=$groupname&keyword=$keyword'><< Back</a> ";
}
for($i=1; $i<=$Num_Pages; $i++){
if($i != $Page)
{
echo " <a class='btn btn-success' href='$_SERVER[SCRIPT_NAME]?Page=$i&groupname=$groupname&keyword=$keyword'>$i</a> ";
}
else
{
echo "<b> $i </b>";
}
}
if($Page!=$Num_Pages)
{
echo " <a class='btn btn-success' href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page&groupname=$groupname&keyword=$keyword'>Next>></a> ";
}
mysql_close();
?>
</div>
</div>
</div>
</div>
</header>
<!-- จบแสดงข้อมูล -->
|
|
|
|
|
Date :
2017-12-26 14:58:52 |
By :
อรวรรณ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|