ต้องการให้ข้อมูลแสดงผล ตอนแรกขึ้น error ว่า Warnin

สำหรับผู้ที่ เริ่มต้น Programming - PHP มีอะไร แนะนำ หรือข้อสงสัยต้องบอร์ด นี้ คนที่มีความรู้ แบ่งปันคนอื่นบ้างนะ ปัญหาการเขียนโปรแกรม แบบ OOP Session Cookies php network

Moderator: mindphp, ผู้ดูแลกระดาน

Jsk
PHP Newbie
PHP Newbie
โพสต์: 7
ลงทะเบียนเมื่อ: 04/04/2017 8:54 pm

ต้องการให้ข้อมูลแสดงผล ตอนแรกขึ้น error ว่า Warnin

โพสต์ที่ยังไม่ได้อ่าน โดย Jsk »

ต้องการให้ข้อมูลแสดงผล ตอนแรกขึ้น error ว่า Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:xampphtdocsprojectwebboard_index.php on line 6


<?php
session_start();
require('Connections/condb.php');
//แสดงหมวดหมุ่กระทู้ทั้งหมดโดยเรียงตามลำดับ cg_order จากน้อยไปมาก
$rs_category = mysql_query("SELECT * FROM category_board ORDER BY cg_order ASC");
$chk_rows_category=mysql_num_rows($rs_category); //นับจำนวนแถวของหมวดกระทู้ ----->ส่วนที่ error
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="css/bootstrap.min.css" rel="stylesheet">
<link rel="icon" href="image/connn.png" type="image/x-icon"/>
</head>
<body>

<div class="container">
<?php require('header.php'); ?>
<div class="row ws-content">
<table class="table table-hover">
<thead>
<tr>
<th>หมวดกระทู้</th>
<th class="hidden-xs" align="center">หัวข้อกระทู้</th>
<th class="hidden-xs" align="center">ความคิดเห็น</th></tr>
</thead>
<tbody>
<?php
if ($chk_rows_category > 0) {//จำนวนแถวมากกว่า 0 แสดงว่ามีข้อมูล
while ($show_category = mysql_fetch_assoc($rs_category)) {
$cg_id = $show_category['cg_id'];
$cg_name = $show_category['cg_name'];
$cg_des = $show_category['cg_des'];
$cg_v = $show_category['cg_replie_totals'];
$cg_tp_total = $show_category['cg_topic_totals'];
?>
<tr>
<td style="width:80%">
<a href="showboard.php?id=<?php echo $cg_id; ?>"><?php echo $cg_name; ?></a>
<br /><?php echo $cg_des; ?>
</td>
<td style="width:10%" class="hidden-xs" align="center"><?php echo $cg_tp_total; ?></td>
<td style="width:10%" class="hidden-xs" align="center"><?php echo $cg_v; ?></td>
</tr>
<?php
}
} else { //ไม่มีข้อมูลหมวดกระทู้
?>
<tr>
<td colspan="3" align="center"><strong>ไม่พบข้อมูล</strong></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
<?php require('footer.php'); ?>
<script src="js/jquery-3.1.1.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>


หลังจากนั้นได้ใส่ or die mysql_error() แสดงผล no database select
และเอาโค๊ดมาประยุกต์ดู แต่ก็ยังขึ้น no database select

<?php
session_start();
require('Connections/condb.php');
?>
<?php
$hostname_condb = "localhost";
$database_condb = "animal_project";
$username_condb = "root";
$password_condb = "";
$condb = mysql_pconnect($hostname_condb, $username_condb, $password_condb) or trigger_error(mysql_error(),E_USER_ERROR);
mysql_query("SET NAMES UTF8");
//แสดงหมวดหมุ่กระทู้ทั้งหมดโดยเรียงตามลำดับ cg_order จากน้อยไปมาก
$rs_category ="SELECT * FROM category_board ORDER BY cg_order ASC";
$rs_category = mysql_query($rs_category) or die(mysql_error());
$chk_rows_category = mysql_num_rows($rs_category);
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="css/bootstrap.min.css" rel="stylesheet">
<link rel="icon" href="image/connn.png" type="image/x-icon"/>


</head>
<body>
<div class="container">
<?php require('header.php'); ?>
<div class="row ws-content">
<table class="table table-hover">
<thead>
<tr>
<th>หมวดกระทู้</th>
<th class="hidden-xs" align="center">หัวข้อกระทู้</th>
<th class="hidden-xs" align="center">ความคิดเห็น</th></tr>
</thead>
<tbody>
<?php
if ($chk_rows_category > 0) {//จำนวนแถวมากกว่า 0 แสดงว่ามีข้อมูล
while ($show_category = mysql_fetch_assoc($rs_category)) {
$cg_id = $show_category['cg_id'];
$cg_name = $show_category['cg_name'];
$cg_des = $show_category['cg_des'];
$cg_v = $show_category['cg_replie_totals'];
$cg_tp_total = $show_category['cg_topic_totals'];
?>
<tr>
<td style="width:80%">
<a href="showboard.php?id=<?php echo $cg_id; ?>"><?php echo $cg_name; ?></a>
<br /><?php echo $cg_des; ?>
</td>
<td style="width:10%" class="hidden-xs" align="center"><?php echo $cg_tp_total; ?></td>
<td style="width:10%" class="hidden-xs" align="center"><?php echo $cg_v; ?></td>
</tr>
<?php
}
} else { //ไม่มีข้อมูลหมวดกระทู้
?>
<tr>
<td colspan="3" align="center"><strong>ไม่พบข้อมูล</strong></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
<?php require('footer.php'); ?>
<script src="js/jquery-3.1.1.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>
เกิดจากอะไรเหรอคะ
ภาพประจำตัวสมาชิก
mindphp
ผู้ดูแลระบบ MindPHP
ผู้ดูแลระบบ MindPHP
โพสต์: 41131
ลงทะเบียนเมื่อ: 22/09/2008 6:18 pm
ติดต่อ:

Re: ต้องการให้ข้อมูลแสดงผล ตอนแรกขึ้น error ว่า Warnin

โพสต์ที่ยังไม่ได้อ่าน โดย mindphp »

ลอง echo mysql_error()
ที่ line 6
ติดตาม VDO: http://www.youtube.com/c/MindphpVideoman
ติดตาม FB: https://www.facebook.com/pages/MindphpC ... 9517401606
หมวดแชร์ความรู้: https://www.mindphp.com/forums/viewforum.php?f=29
รับอบรม และพัฒนาระบบ: https://www.mindphp.com/forums/viewtopic.php?f=6&t=2042
Jsk
PHP Newbie
PHP Newbie
โพสต์: 7
ลงทะเบียนเมื่อ: 04/04/2017 8:54 pm

Re: ต้องการให้ข้อมูลแสดงผล ตอนแรกขึ้น error ว่า Warnin

โพสต์ที่ยังไม่ได้อ่าน โดย Jsk »

ลองแล้วคะ หลังจากนั้นขึ้น no database selected
bom_002
PHP Super Member
PHP Super Member
โพสต์: 443
ลงทะเบียนเมื่อ: 06/03/2017 10:51 am

Re: ต้องการให้ข้อมูลแสดงผล ตอนแรกขึ้น error ว่า Warnin

โพสต์ที่ยังไม่ได้อ่าน โดย bom_002 »

ลองตรวจสอบชื่อ table ในฐานข้อมูลดูครับ อาจจะมีช่องว่างอยู่ก็เป็นได้ :-D
:plusone:
ตอบกลับโพส
  • Similar Topics
    ตอบกลับ
    แสดง
    โพสต์ล่าสุด

ผู้ใช้งานขณะนี้

สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 61