douqiang6448 2013-12-10 14:31
浏览 24
已采纳

在php中查看数据表中的所有错误[关闭]

When i run it. i only see 1 records of customer and it says that the error is in " WHILE($cus = mysql_fetch_array($cus)){" Line.. anyone knows how to solve it? ..tnx

<table id="datatables" class="display">

    <thead>

        <tr>
            <th>ID</th>
            <th>FullName</th>
            <th>Age</th>
            <th>Gender</th>
            <th>Email</th>
            <th>Barangay</th>
            <th>CompleteAddress</th>
            <th>Username</th>
            <th>Password</th>
        </tr>

    </thead>

    <tbody>

        <?php $cus = mysql_query("SELECT * FROM customer") or die(mysql_error()); ?>

        <?php
        WHILE ($cus = mysql_fetch_array($cus)) {

            $id = $cus['cus_id'];
            $email = $cus['email'];
            $control = $cus['cus_id'];
            $user = $cus['username'];
            $pass = $cus['password'];
            $brgy = $cus['barangay'];
            $comadd = $cus['com_address'];
            $age = $cus['age'];
            $gend = $cus['gender'];

            $fname = $cus['firstname'] . "&nbsp;" . $cus['middlename'] . "&nbsp;" . $cus['lastname'];
            ?>

            <tr class="gradeA del<?php echo $id; ?>">
                <td><?php echo $control; ?></td>
                <td><?php echo $fname; ?></td>
                <td><?php echo $age; ?></td>
                <td><?php echo $gend; ?></td>
                <td><?php echo $email; ?></td>
                <td><?php echo $brgy; ?></td>
                <td><?php echo $comadd; ?></td>
                <td><?php echo $user; ?></td>
                <td><?php echo $pass; ?></td>

            </tr>

            <?php
        }
        ?>

    </tbody>
</table>
  • 写回答

5条回答 默认 最新

  • doucang6739 2013-12-10 14:52
    关注

    you can't use $cus as the result set for the query and the row information. one of these variables needs to be something different. in my comment above, I suggested turning one into row but it's a lot easier to just change the name of the result set, so that is what I did in the code below.

    I assume you have the correct connection set up before your pasted code starts, too.

    <table id="datatables" class="display">
    
        <thead>
    
            <tr>
                <th>ID</th>
                <th>FullName</th>
                <th>Age</th>
                <th>Gender</th>
                <th>Email</th>
                <th>Barangay</th>
                <th>CompleteAddress</th>
                <th>Username</th>
                <th>Password</th>
            </tr>
    
        </thead>
    
        <tbody>
    
            <?php 
    
            // this used to be $cus but I renamed it... 
            $customer_results = mysql_query("SELECT * FROM customer") or die(mysql_error());  
    
            //  here was the issue... you were using $cus twice.  
            WHILE ($cus = mysql_fetch_array($customer_results)) 
            { 
                $id = $cus['cus_id'];
                $email = $cus['email'];
                $control = $cus['cus_id'];
                $user = $cus['username'];
                $pass = $cus['password'];
                $brgy = $cus['barangay'];
                $comadd = $cus['com_address'];
                $age = $cus['age'];
                $gend = $cus['gender'];
    
                $fname = $cus['firstname'] . "&nbsp;" . $cus['middlename'] . "&nbsp;" . $cus['lastname'];
                ?>
    
                <tr class="gradeA del<?php echo $id; ?>">
                    <td><?php echo $control; ?></td>
                    <td><?php echo $fname; ?></td>
                    <td><?php echo $age; ?></td>
                    <td><?php echo $gend; ?></td>
                    <td><?php echo $email; ?></td>
                    <td><?php echo $brgy; ?></td>
                    <td><?php echo $comadd; ?></td>
                    <td><?php echo $user; ?></td>
                    <td><?php echo $pass; ?></td>
    
                </tr>
    
                <?php
            }
            ?>
    
        </tbody>
    </table>
    

    Keep in mind, mysql functions are old and will be removed from PHP. You should not waste your time learning them. Instead use PDO or MYSQLI. Personally, I think PDO is easier. If you decide to switch over to one of those two new DB classes, be sure to parameterize your queries and bind values to help prevent SQL injection.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)