TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 07-19-2009, 06:29 AM   #1 (permalink)
The Visitor
Newcomer 
 
Join Date: Jul 2009
Posts: 1
Thanks: 0
gtifllm is on a distinguished road
Default Nested while loop needed for this?

Hello. I'm trying to display a MySQL timestamp in the user's timezone for each entry in a databse table. BTW, this is OsCommerce, so disregard the weird function names.

This code converts the timestamp for one entry....
PHP Code:
$timestamp_from_mysql tep_db_query("SELECT UNIX_TIMESTAMP(`date_added`) FROM `".TABLE_TUTORING_UNITS_COMMENTS."` WHERE `customers_id` = '".$customer_id."' ORDER BY `date_added`");
$timezone_from_mysql tep_db_query("SELECT `customers_timezone` FROM `".TABLE_CUSTOMERS."` WHERE `customers_id` = '".$customer_id."'");

if(
$timestamp_from_mysql!=false&&$timezone_from_mysql!=false){
        
$timestamp_from_mysql=tep_db_fetch_array($timestamp_from_mysql);
        
$timezone_from_mysql=tep_db_fetch_array($timezone_from_mysql);
        
        
$timestamp=$timestamp_from_mysql['UNIX_TIMESTAMP(`date_added`)']; 
        
$timezone=$timezone_from_mysql['customers_timezone'];
        
        
$dt_zone=new DateTimeZone($timezone);
        
$time=date('r',$timestamp);
        
$dtime=new DateTime($time);
        
$dtime->setTimeZone($dt_zone);
                            
        echo 
$dtime->format("M. j, Y \a\\t g:i a");


This is my current code...
PHP Code:
    $tutoring_comments_query tep_db_query("select comments from " TABLE_TUTORING_UNITS_COMMENTS " where customers_id = '" . (int)$customer_id "' order by date_added");

    if (
tep_db_num_rows($tutoring_comments_query)) {
      while (
$tutoring_comments tep_db_fetch_array($tutoring_comments_query)) {

          
$timezone_from_mysql tep_db_query("SELECT `customers_timezone` FROM `".TABLE_CUSTOMERS."` WHERE `customers_id` = '".$customer_id."'");
        
$timestamp_from_mysql tep_db_query("SELECT UNIX_TIMESTAMP(`date_added`) FROM `".TABLE_TUTORING_UNITS_COMMENTS."` WHERE `customers_id` = '".$customer_id."' ORDER BY `date_added`");

          if(
$timestamp_from_mysql!=false&&$timezone_from_mysql!=false){
        
$timestamp_from_mysql=tep_db_fetch_array($timestamp_from_mysql);
        
$timezone_from_mysql=tep_db_fetch_array($timezone_from_mysql);
        
        
$timestamp=$timestamp_from_mysql['UNIX_TIMESTAMP(`date_added`)']; 
        
$timezone=$timezone_from_mysql['customers_timezone'];
        
        
$dt_zone=new DateTimeZone($timezone);
        
$time=date('r',$timestamp);
        
$dtime=new DateTime($time);
        
$dtime->setTimeZone($dt_zone);
        }

      echo 
'          <tr>' "\n" .
             
'            <td class="main" align="center">' '&nbsp;' $dtime->format("M. j, Y \a\\t g:i a") . '&nbsp;' '</td>' "\n" .
             
'            <td class="main" align="center">' '&nbsp;';
        if (
$orders_history['customer_notified'] == '1') {
          echo 
tep_image(DIR_WS_ICONS 'tick.gif'ICON_TICK) . '&nbsp;' "</td>\n";
        } else {
          echo 
tep_image(DIR_WS_ICONS 'cross.gif'ICON_CROSS) . '&nbsp;' "</td>\n";
        }
        echo 
'            <td class="main">' '&nbsp;' nl2br(tep_db_output($tutoring_comments['comments'])) . '&nbsp;</td>' "\n" .
             
'          </tr>' "\n";
      }
    } else {
        echo 
'          <tr>' "\n" .
             
'            <td class="main" colspan="5">&nbsp;There are no tutoring comments at this time.</td>' '&nbsp;' "\n" .
             
'          </tr>' "\n";
    } 

Currently, I'm getting several entries so I know the main while loop is working. It's just that the timestamps that come from that are all displaying the time of the first entry instead of the time for each entry. So, it seems like the second while loop (the one for converting the timezone) is only getting run once.

I'm not married to the nested while structure. If someone has a better idea, please enlighten me.

Thanks!
gtifllm is offline  
Reply With Quote
Old 08-17-2009, 07:50 PM   #2 (permalink)
The Wanderer
 
Join Date: Aug 2009
Posts: 11
Thanks: 1
jasonberresford is on a distinguished road
Default

Yep ...

ob_flush();
flush();
clearstatcache();


Ran into the same problem for a daemon running a php loop.. Time wouldn't change any time during the loop.. Clear the stat cache .. and you should be good.
jasonberresford is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Nested While Loop Issue Jako General 3 08-06-2008 06:13 AM
Horizontal nested loop problem Dracula General 3 06-05-2008 03:12 PM
Another quetion - Loop inside a loop Jmz General 1 05-30-2008 09:07 PM
Need help on nested loop! pabin Absolute Beginners 4 05-12-2008 10:27 AM
Best Way To Loop In A Table? StevenF Absolute Beginners 16 03-14-2008 04:26 PM


All times are GMT. The time now is 12:09 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design