Changing part of a query before displaying it
am 15.07.2009 19:10:43 von Don Collier
I am quite new at this so please bare with me.
I am getting a several rows of data from a database to display in a
table. One of the fields is in a format that I want to change before
putting it in the table. The field is time in seconds, but I want it to
be displayed in minutes instead. Below is what I have to get the data
into the table.
while ($row = mysql_fetch_row($result10)) {
print '
';
foreach($row as $data) {
print " {$data} | ";
}
print '
';
There are 6 columns in the table and the column that I want to change is
the 3rd one.
How do I go about doing this?
Don Collier
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Changing part of a query before displaying it
am 15.07.2009 19:38:49 von Patrick Price
--0016e6475b0451bbe2046ec208cc
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
I believe your best bet is to change how you are iterating through the $row
data.
Since there are only 6 columns of data, I think the simplest solution is to
remove the foreach() and handle each column's data independently, ie:
while($row = mysql_fetch_row($result10))
{
print '
' . $row['first_column'] . ' |
' . $row['second_column'] . ' |
' . $row['third_column']/60 . ' |
' . $row['fourth_column'] . ' |
' . $row['fifth_column'] . ' |
' . $row['sixth_column'] . ' |
';
}
Thanks
patrick
On Wed, Jul 15, 2009 at 1:10 PM, Don Collier wrote:
> I am quite new at this so please bare with me.
> I am getting a several rows of data from a database to display in a table.
> One of the fields is in a format that I want to change before putting it in
> the table. The field is time in seconds, but I want it to be displayed in
> minutes instead. Below is what I have to get the data into the table.
>
> while ($row = mysql_fetch_row($result10)) {
> print '';
> foreach($row as $data) {
> print " {$data} | ";
> }
> print '
';
>
> There are 6 columns in the table and the column that I want to change is
> the 3rd one.
>
> How do I go about doing this?
>
> Don Collier
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--0016e6475b0451bbe2046ec208cc--
Re: Changing part of a query before displaying it
am 15.07.2009 19:40:59 von Don Collier
Would that work for multiple rows though? This is getting a varying
number of rows.
Patrick Price wrote:
> I believe your best bet is to change how you are iterating through the
> $row data.
>
> Since there are only 6 columns of data, I think the simplest solution
> is to remove the foreach() and handle each column's data
> independently, ie:
> while($row = mysql_fetch_row($result10))
> {
> print '
>
> ' . $row['first_column'] . ' |
> ' . $row['second_column'] . ' |
> ' . $row['third_column']/60 . ' |
> ' . $row['fourth_column'] . ' |
> ' . $row['fifth_column'] . ' |
> ' . $row['sixth_column'] . ' |
>
';
> }
>
> Thanks
>
> patrick
>
>
> On Wed, Jul 15, 2009 at 1:10 PM, Don Collier
> > wrote:
>
> I am quite new at this so please bare with me.
> I am getting a several rows of data from a database to display in
> a table. One of the fields is in a format that I want to change
> before putting it in the table. The field is time in seconds, but
> I want it to be displayed in minutes instead. Below is what I
> have to get the data into the table.
>
> while ($row = mysql_fetch_row($result10)) {
> print '';
> foreach($row as $data) {
> print " {$data} | ";
> }
> print '
';
>
> There are 6 columns in the table and the column that I want to
> change is the 3rd one.
>
> How do I go about doing this?
>
> Don Collier
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Changing part of a query before displaying it
am 15.07.2009 19:51:31 von Patrick Price
--0016363b7b74c13946046ec2355c
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Yes, the while loop will retrieve all the rows from the database.
The foreach loop you had been using was retrieving all the data from each
row. The only appreciable difference between your code and mine is in the
circumstance, if you added more columns to the database, you would need to
add more code to access that data in my code, whereas your code you wouldn't
need to add any more code.
Thanks
patrick
On Wed, Jul 15, 2009 at 1:40 PM, Don Collier wrote:
> Would that work for multiple rows though? This is getting a varying number
> of rows.
> Patrick Price wrote:
>
>> I believe your best bet is to change how you are iterating through the
>> $row data.
>> Since there are only 6 columns of data, I think the simplest solution is
>> to remove the foreach() and handle each column's data independently, ie:
>> while($row = mysql_fetch_row($result10))
>> {
>> print '
>>
>> ' . $row['first_column'] . ' |
>> ' . $row['second_column'] . ' |
>> ' . $row['third_column']/60 . ' |
>> ' . $row['fourth_column'] . ' |
>> ' . $row['fifth_column'] . ' |
>> ' . $row['sixth_column'] . ' |
>>
';
>> }
>>
>> Thanks
>>
>> patrick
>>
>>
>> On Wed, Jul 15, 2009 at 1:10 PM, Don Collier
>> don@collierclan.com>> wrote:
>>
>> I am quite new at this so please bare with me.
>> I am getting a several rows of data from a database to display in
>> a table. One of the fields is in a format that I want to change
>> before putting it in the table. The field is time in seconds, but
>> I want it to be displayed in minutes instead. Below is what I
>> have to get the data into the table.
>>
>> while ($row = mysql_fetch_row($result10)) {
>> print '';
>> foreach($row as $data) {
>> print " {$data} | ";
>> }
>> print '
';
>>
>> There are 6 columns in the table and the column that I want to
>> change is the 3rd one.
>>
>> How do I go about doing this?
>>
>> Don Collier
>>
>> -- PHP Database Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>>
--0016363b7b74c13946046ec2355c--