-1

Hey again, posted the same code but seems like no one really answered, solved most erros alone, but still need help.

What shows up on localhost:

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\Projeto\all.php on line 71
Showing 1 - 0 results from the total of 7 separated in 2 pages.


Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\Projeto\all.php on line 121

all.php

<h2>List of all the users</h2>
<div class="center_float">

    <?php
    require 'conf/connection.php';

    $number = 5;

    if (isset($_GET['order'])) {
        $mode = $_GET['mode'];
        $order = $_GET['order'];
    } else {
        $mode = "UP";
        $order = "name";
    }

    function mode($order, $mode, $current) {
        if ($order == $current) {
            if ($mode == "UP") {
                $mode = "DOWN";
            } else {
                $mode = "UP";
            }
        } else {
            $mode = "UP";
        }
        return $mode;
    }

    function mode_complete($order, $mode, $current) {
        if ($order == $current) {
            if ($mode == "UP") {
                $mode_complete = "Up";
            } else {
                $mode_complete = "Down";
            }
        } else {
            $mode_complete = "Up";
        }
        return $mode_complete;
    }

    function arrow($order, $mode, $current) {
        if ($order == $current) {
            $img_id = "ord_" . $order;
            echo "<img src='img/" . $mode . ".png' id='" . $img_id . "'>";
        }
    }

    function mouse($order, $mode, $current) {
        if ($order == $current) {
            $img_id = "ord_" . $order;
            $mode_over = ($mode == "UP") ? "DOWN" : "UP";
            echo "onmouseover='order(\"" . $img_id . "\",\"" . $mode_over . "\")' ";
            $mode_out = ($mode == "UP") ? "UP" : "DOWN";
            echo "onmouseout='order(\"" . $img_id . "\",\"" . $mode_out . "\")' ";
        }
    }

    if (isset($_GET['page'])) {
        $page = (int) $_GET['page'];
        $home = ($page - 1) * $number;
    } else {
        $page = 1;
        $home = 0;
    }

    $total_selection = mysql_query("SELECT * FROM users");
    $total = mysql_num_rows($total_selection);
    $r = mysql_query("SELECT * FROM users ORDER BY $order $mode LIMIT $home, $number");
    $total2 = mysql_num_rows($r);
    $final_number2 = $home + $total2;
    $value = ceil($total / $number);
    $start_number = $home + 1;
    $final_number = $home + $number;

    if ($total == 0) {
        echo "<p>No users registered.</p>";
    } elseif ($total == 1) {
        echo "<p>There's only <b>1</b> user registered.</p>";
    }

    if ($total > 1) {
        if ($value > 1) {
            if ($total2 < $number) {
                if ($start_number == $final_number2) {
                    echo "<p>Showing <b>1</b> result from the total of <b>$total</b> separated in <b>$value</b> page.</p>";
                } else {
                    echo "<p>Showing <b>$start_number</b> - <b>$final_number2</b> results from the total of <b>$total</b> separated in <b>$value</b> pages.</p>";
                }
            } else {
                echo "<p>Showing <b>$start_number</b> - <b>$final_number</b> results from the total of <b>$total</b> separated in <b>$value</b> pages.</p>";
            }
        } else {
            echo "<p>Showing <b>$total</b> results in <b>1</b> page.</p>";
        }
    }

    if ($total) {
        if ($page >= 1 && $page <= $value) {
            ?>

            <br>
            <table class="tab_all">

                <tr>
                    <th width="30"><a href="?p=all&page=<?php echo $page ?>&order=id&mode=<?php echo mode($order, $mode, 'id') ?>" title="Order per ID <?php echo mode_complete($order, $mode, 'id') ?>" <?php echo mouse($order, $mode, 'id') ?> class="lth">ID <?php arrow($order, $mode, 'id') ?></a></th>
                    <th width="220"><a href="?p=all&page=<?php echo $page ?>&order=name&mode=<?php echo mode($order, $mode, 'name') ?>" title="Order per Name <?php echo mode_complete($order, $mode, 'name') ?>" <?php echo mouse($order, $mode, 'name') ?> class="lth">Name <?php arrow($order, $mode, 'name') ?></a></th>
                    <th width="70"><a href="?p=all&page=<?php echo $page ?>&order=username&mode=<?php echo mode($order, $mode, 'username') ?>" title="Order per Username <?php echo mode_complete($order, $mode, 'username') ?>" <?php echo mouse($order, $mode, 'username') ?> class="lth">Username <?php arrow($order, $mode, 'username') ?></th>
                    <th width="70"><a href="?p=all&page=<?php echo $page ?>&order=password&mode=<?php echo mode($order, $mode, 'password') ?>" title="Order per Password <?php echo mode_complete($order, $mode, 'password') ?>" <?php echo mouse($order, $mode, 'password') ?> class="lth">Password <?php arrow($order, $mode, 'password') ?></th>
                    <th width="170"><a href="?p=all&page=<?php echo $page ?>&order=email&mode=<?php echo mode($order, $mode, 'email') ?>" title="Order per E-mail <?php echo mode_complete($order, $mode, 'email') ?>" <?php echo mouse($order, $mode, 'email') ?> class="lth">E-mail <?php arrow($order, $mode, 'email') ?></th>
                    <th width="80"><a href="?p=all&page=<?php echo $page ?>&order=birth_date&mode=<?php echo mode($order, $mode, 'birth_date') ?>" title="Order per Birth Date <?php echo mode_complete($order, $mode, 'birth_date') ?>" <?php echo mouse($order, $mode, 'birth_date') ?> class="lth">Birth Date <?php arrow($order, $mode, 'birth_date') ?></th>
                    <th width="80"><a href="?p=all&page=<?php echo $page ?>&order=register_date&mode=<?php echo mode($order, $mode, 'register_date') ?>" title="Order per Register Date <?php echo mode_complete($order, $mode, 'register_date') ?>" <?php echo mouse($order, $mode, 'register_date') ?> class="lth">Register Date <?php arrow($order, $mode, 'register_date') ?></th>
                    <th width="50">Edit</th>
                    <th width="50">Delete</th>
                </tr>

                <?php
                $counter = 0;

                while ($info = mysql_fetch_array($r)) {
                    $class = ($counter % 2 == 0) ? 'odd' : 'even';
                    $counter++;

                    $birth_date = explode("-", $info['birth_date']);
                    $birth_date = $birth_date[2] . '-' . $birth_date[1] . '-' . $birth_date[0];

                    $register_date = explode("-", $info['register_date']);
                    $register_date = $register_date[2] . '-' . $register_date[1] . '-' . $register_date[0];

                    echo "<tr class=\"$class\">";
                    echo "<td>" . $info['id'] . "</td>";
                    echo "<td class=\"left\">" . $info['name'] . "</td>";
                    echo "<td>" . $info['username'] . "</td>";
                    echo "<td>" . $info['password'] . "</td>";
                    echo "<td>" . $info['email'] . "</td>";
                    echo "<td>" . $birth_date . "</td>";
                    echo "<td>" . $register_date . "</td>";
                    echo "<td><a href='?p=edit&id=" . $info['id'] . "' title='Edit'><img src='img/edit.png'></a></td>";
                    echo "<td><a href='conf/delete.php?id=" . $info['id'] . "&action=delete' title='Delete'><img src='img/delete.png' onclick='return confirm(\"Are you sure you want to delete " . $info['name'] . "?\")'></a></td>";
                    echo "</tr>";
                }
                ?>
            </table>
            <br>
            <?php
            $previous = $page - 1;
            $next = $page + 1;

            if ($page > 1) {
                echo '<a href="?p=all&page=' . $previous . '" class="paging">« Previous</a>';
            } else {
                echo '<span class="deactivated">« Previous</span>';
            }

            if ($value > 1) {
                for ($i = 1; $i <= $value; $i++) {
                    $class = ($i == $page) ? 'current_paging' : 'paging';
                    echo '<a href="?p=all&page=' . $i . '" class="' . $class . '">' . $i . '</a>';
                }
            }
            if ($page < $value) {
                echo '<a href="?p=all&page=' . $next . '" class="paging">Next »</a>';
            } else {
                echo '<span class="deactivated">Next »</span>';
            }
        } else {
            echo "<p>This page doesn't exist.</p>";
        }
    }
    mysql_close($connection);
    ?>

</div>

Edited by richaell: n/a

3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by mikulucky
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.