tags:

views:

29

answers:

2

Hi friends my database is

CREATE TABLE `mytable` (
       `id` int(10) AUTO_INCREMENT,
       `name` varchar(50),
       `description` varchar(255),
       `visible` varchar(10),
       PRIMARY KEY (`id`)
    ) ENGINE=MyISAM DEFAULT CHARSET utf8;

and php code is

     $display = query("SELECT * FROM mytable ORDER BY id ASC");
     foreach($display as $row) {
      echo $row['id'];
      echo $row['name'];
      echo $row['description'];     
}

what is wrong in my code ? data is not displayed and when it display only first letter of field is displayed. All the configuration and connection settings are fine. Pls help

+1  A: 
var_dump($row);
zerkms
it displays int(4)string(4) "sdfs"string(12) "fsgdfgfdgfds"string(3) "dgd"
sagarmatha
How do I retrieve array values ? please help.
sagarmatha
well, you have no array then - you have only scalar value in `$row`
zerkms
@sagarmatha you need to show your `query()` function. We cannot know what it does.
Pekka
+1  A: 

Looks like it's the same pitfall I fell into once :)
Don't you have only one row in your table?
If this query() function is kinda too smart one, determining return type by returned data, it can be a reason.
Make it return nested array, not one row. And define result type explicitly, not automatically based on returned data. Add a parameter to indicate what kind of result you want.

However, such a function is very good approach. Only a few people have an idea of devising such a function instead of constant hassle with numerous API functions.

but if you expect just one row, then

$row = query("SELECT * FROM mytable ORDER BY id ASC");
echo $row['id'];
echo $row['name'];
echo $row['description'];     
Col. Shrapnel