Re: changing output method

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



u already seem to have a table-like format (after u make the changes
graeme mentioned) to get it as
CompanyName     :Data
Address         :Data
City            :Data
Zipcode         :Data

i'm assuming u want to do something like
CompanyName   Address   City   Zipcode
:Data        :Data       :Data      :Data
:Data        :Data       :Data      :Data
...
:Data        :Data       :Data      :Data

ur table struct:
On Tue, 01 Mar 2005 14:24:44 +0530, chintan <chintanonnet@xxxxxxxxxxx> wrote:
> 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    |       |
> +--------------+--------------+------+-----+---------+-------+
> 

print the headings first.
then in a separate loop, get (and print) the data.

       $query = "SELECT * FROM stockiestandbookingagents";
       $result = mysql_query($query) or die("Query failed");

$num_fields = mysql_num_fields($result);
// e.g. 5 in ur case
// assigned it coz i'll re-use it, no need to keep re-checking /
re-calling that function

//get headers / column names
$i=0;
while($i < $num_fields)
{
        echo (mysql_field_name($result, $i));
        print "\t";
        $i++;
}
print "\n"; //go to a new line after printing headings

// below this is where u actually start extracting rows
// from the table into php variables.

while ($line = mysql_fetch_array($result))
{
        $i=0;
        while($i < $num_fields)
        {
                echo $line[$i];
                print "\t";
                $i++;
        }
        // the above loop is similar to how u'd extract the field
names. the echo line is different but both use $i
        
        print "\n"; // newline after each record is printed
}

check out http://php.net/manual/en/function.mysql-fetch-assoc.php and
http://php.net/manual/en/function.mysql-fetch-row.php
(they're both related to mysql_fetch_aray)

if u are doing this for specific tables and it's not a generic select
* from $any_table type query, then don't keep getting the field names.
echo it before the while loop above. fetching the field names is ok if
they are descriptive enough for output.

btw, ppl generally use <table>s to get a decently formatted table
layout...the columnar. replace ur echo "\t" with <td> and "\n" with
<tr>. make sure u have matching tags wehn u do this. google.

hth

-- 
]#
Anirudh Dutt


...pilot of the storm who leaves no trace
like thoughts inside a dream

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux