Re: changing output method

From: Date: Tue, 01 Mar 2005 10:22:52 +0000
Subject: Re: changing output method
References: 1 2 3  Groups: php.db 
Request: Send a blank email to php-db+get-38724@lists.php.net to get a copy of this message
Try putting your print "\t$col_value\n" immediately after the foreach... foreach ($line as $col_value)
       print "\t$col_value\n";
remember to remove teh semi-colon after the foreach line. graeme. chintan wrote:
as usual my database is in mysql and there are lots of records available i had wrote my script like this $link = mysql_connect("localhost", "chintan","hellomysql")
    or die("Could not connect");
    mysql_select_db("chintan") or die("Could not select database");
    $query = "SELECT * FROM stockiestandbookingagents";
    $result = mysql_query($query) or die("Query failed");
    $i=0;
    while($i<mysql_num_fields($result))
        {
        echo (mysql_field_name($result, $i));
        print "\t";
        while ($line = mysql_fetch_array($result))
                    {
                    foreach ($line as $col_value);
                    }
        $i++;
        print "\t$col_value\n";
        }
    mysql_free_result($result);
    mysql_close($link);
but it just displays the pincode of the city only(the last column) the table structure is like below; +--------------+--------------+------+-----+---------+-------+
| Field        | Type         | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+-------+
| CompanyName  | varchar(50)  |      | PRI |         |       |
| AddressLine1 | varchar(100) | YES  |     | NULL    |       |
| AddressLine2 | varchar(100) | YES  |     | NULL    |       |
| City         | varchar(50)  | YES  |     | NULL    |       |
| PostalCode   | varchar(50)  | YES  |     | NULL    |       |
+--------------+--------------+------+-----+---------+-------+
-- Experience is a good teacher, but she sends in terrific bills. Minna Antrim

« previous php.db (#38724) next »