Ask about a PHP problem here.
-
EcazS
- Posts: 789
- Joined: Fri May 06, 2011 5:29 pm
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
-
JelvinJS7
- Posts: 341
- Joined: Thu May 12, 2011 8:40 pm
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…
-
EcazS
- Posts: 789
- Joined: Fri May 06, 2011 5:29 pm
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
Post
by Tino »
Try removing that first fetch statement, so that you only keep the one in the while loop.
-
EcazS
- Posts: 789
- Joined: Fri May 06, 2011 5:29 pm
Post
by EcazS »
Dear god I'm blind!
How could I not see that
-
Tino
- Posts: 360
- Joined: Thu May 05, 2011 8:55 pm
- Location: The Netherlands
Post
by Tino »
Well you just said you are blind, so...