Fetches all but one?!

Ask about a PHP problem here.
Post Reply
User avatar
EcazS
Posts: 789
Joined: Fri May 06, 2011 5:29 pm

Fetches all but one?!

Post 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:
JelvinJS7
Posts: 341
Joined: Thu May 12, 2011 8:40 pm

Re: Fetches all but one?!

Post 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…
User avatar
EcazS
Posts: 789
Joined: Fri May 06, 2011 5:29 pm

Re: Fetches all but one?!

Post 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 />";
    }
:?
Tino
Posts: 360
Joined: Thu May 05, 2011 8:55 pm
Location: The Netherlands

Re: Fetches all but one?!

Post by Tino »

Try removing that first fetch statement, so that you only keep the one in the while loop.
Please check out my CodeCanyon items.
User avatar
EcazS
Posts: 789
Joined: Fri May 06, 2011 5:29 pm

Re: Fetches all but one?!

Post by EcazS »

Dear god I'm blind! :shock:

How could I not see that :roll:
Tino
Posts: 360
Joined: Thu May 05, 2011 8:55 pm
Location: The Netherlands

Re: Fetches all but one?!

Post by Tino »

Well you just said you are blind, so... ;)
Please check out my CodeCanyon items.
Post Reply