Page 1 of 1

Fetches all but one?!

Posted: Sun Jun 12, 2011 11:45 pm
by EcazS
In my table I have A B C D,
                $mysql->query("
                    SELECT
                        `name`
                    FROM `categories` ORDER BY `name` ASC
                ");

                $mysql->fetch($row);

                $return = array();
                while ($mysql->fetch($row)){
                    $return[] = $row;
                }

                return $return;
and then,
foreach($rows as $row) {
        echo $row['name'];
        echo "<br />";
}
but here is the weird thing, it only echoes B C D and if I change the order to DESC it echoes C B A I never run into this problem before :shock:

Re: Fetches all but one?!

Posted: Mon Jun 13, 2011 3:36 am
by JelvinJS7
Can you post, like, the entire code? That'd make it easier to understand.

At least, for me it would. Idk about anyone elseā€¦

Re: Fetches all but one?!

Posted: Mon Jun 13, 2011 10:09 am
by EcazS
             if($_GET['category'] === "all") {

                $mysql->query("
                    SELECT
                        `name`
                    FROM `categories` ORDER BY `name` ASC
                ");

                $mysql->fetch($row);

                $return = array();
                while ($mysql->fetch($row)){
                    $return[] = $row;
                }

                return $return;

            }
    $categories = new Categories;
    $rows = $categories->GetCategories();

    foreach($rows as $row) {
        echo $row['name'];
        echo "<br />";
    }
:?

Re: Fetches all but one?!

Posted: Mon Jun 13, 2011 12:32 pm
by Tino
Try removing that first fetch statement, so that you only keep the one in the while loop.

Re: Fetches all but one?!

Posted: Mon Jun 13, 2011 12:36 pm
by EcazS
Dear god I'm blind! :shock:

How could I not see that :roll:

Re: Fetches all but one?!

Posted: Mon Jun 13, 2011 12:45 pm
by Tino
Well you just said you are blind, so... ;)