สอบถาม php no database select

ถาม-ตอบ แนะนำไอเดียว โค้ดตัวอย่าง แนวทาง วิธีแก้ปัญหา สอบถาม php no database select

สอบถาม php no database select
ต้องการให้ข้อมูลแสดงผล ตอนแรกขึ้น 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>
เกิดจากอะไรเหรอคะ


Sujan 183.89.28.xxx 16-04-2017 18:58:10

คำแนะนำ และการใช้งาน

สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก


  • ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
  • เปลี่ยน


    ( หรือ เข้าใช้งานผ่าน Social Login )

 ความคิดเห็นที่ 1
ลองดูวิธีการใช้งานนี้เป็นแนวทาง

https://www.ninenik.com/forum_view_2398_1.html#comment_5574


ninenik 1.46.205.xxx 16-04-2017






เว็บไซต์ของเราให้บริการเนื้อหาบทความสำหรับนักพัฒนา โดยพึ่งพารายได้เล็กน้อยจากการแสดงโฆษณา โปรดสนับสนุนเว็บไซต์ของเราด้วยการปิดการใช้งานตัวปิดกั้นโฆษณา (Disable Ads Blocker) ขอบคุณครับ