Re: [PHP-DB] changing output method

2005-03-04 Thread anirudh dutt
put
echo mysql_num_rows($result);
before
while ($line = mysql_fetch_array($result))

and add
print_r($line)
inside the while loop

is $line empty? paste _some_ of that output.

On Fri, 04 Mar 2005 10:52:59 +0530, chintan [EMAIL PROTECTED] wrote:
 and as aniruddh's suggestion i was unable to printout any raws
 it just prints tables fieldname

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



Re: [PHP-DB] changing output method

2005-03-03 Thread chintan
the output looks like this
CompanyName 641002
AddressLine1641002
AddressLine2641002
City641002
PostalCode  641002
it goes to the last field only not one by one
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] changing output method

2005-03-03 Thread chintan
and as aniruddh's suggestion i was unable to printout any raws
it just prints tables fieldname
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] changing output method

2005-03-01 Thread chintan
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($imysql_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|   |
+--+--+--+-+-+---+
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] changing output method

2005-03-01 Thread graeme
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($imysql_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
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] changing output method

2005-03-01 Thread anirudh dutt
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 [EMAIL PROTECTED] 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 tables 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



[PHP-DB] changing output method

2005-02-28 Thread chintan
Hi forum
i have a simple problem
as im new to php how do i set the output type from table to columner 
like below:

CompanyName :Data
Address :Data
City:Data
Zipcode :Data
...
Please help me know that loop i tried very much but i was unable to find 
that out.

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


Re: [PHP-DB] changing output method

2005-02-28 Thread Micah Stevens
There's not enough information from your question to provide a good answer.. 
Where are you getting the data from? 

Is there more than one record available? 

-Micah 

On Monday 28 February 2005 11:05 pm, chintan wrote:
 Hi forum
 i have a simple problem
 as im new to php how do i set the output type from table to columner
 like below:

 CompanyName :Data
 Address  :Data
 City  :Data
 Zipcode  :Data
 ...

 Please help me know that loop i tried very much but i was unable to find
 that out.

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