Phpnewbie23 Posted January 12, 2009 Share Posted January 12, 2009 I am having a issue with a php function. What i am trying to do is populate a table using a ODBC_fetch_row. Here is the code: echo "<table width=60% height=3% cellspacing='1' cellpadding='2' border='1'>"; echo "<tr>"; echo "<th align=center><small>Client</small</th>"; echo "<th align=center><small>Backup Name</small></th>"; echo "<th align=center><small>Start Time</small></th>"; echo "<th align=center><small>End Time</small></th>"; echo "<th align=center><small>Backup Status</small></th>"; echo "</tr>"; //echo "</table>"; while (odbc_fetch_row($rs)) { $client=odbc_result($rs,"CLIENT_NAME"); $backupname=odbc_result($rs,"BACKUP_NAME"); $start_time=odbc_result($rs,"BACKUP_START_TIME"); $end_time=odbc_result($rs,"BACKUP_END_TIME"); $remarks=odbc_result($rs,"REMARKS"); //echo "<table width=60% height=5% cellspacing='1' cellpadding='2' border='1'>"; echo "<tr>"; echo "<td align=center><small>$client</small></td>","\n"; echo "<td align=center><small>$backupname</small></td>","\n"; echo "<td align=center><small>$start_time</small></td>","\n"; echo "<td align=center><small>$end_time</small></td>","\n"; echo "<td align=center><small>$remarks</small></td>","\n"; echo "</tr>"; echo "</table>"; and the result i am getting is see attached image. What i would like to do is have the results in table. Like the first row in the image with $remarks to green if success and red if say SG0000 out of space. I also would like to sort out the time change it from UNIX to windows time and some other stuff but that can been later. Cheers [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
ngreenwood6 Posted January 12, 2009 Share Posted January 12, 2009 try this: echo "<table width=60% height=3% cellspacing='1' cellpadding='2' border='1'>"; echo "<tr>"; echo "<th align=center><small>Client</small</th>"; echo "<th align=center><small>Backup Name</small></th>"; echo "<th align=center><small>Start Time</small></th>"; echo "<th align=center><small>End Time</small></th>"; echo "<th align=center><small>Backup Status</small></th>"; echo "</tr>"; //echo "</table>"; while (odbc_fetch_row($rs)) { $client=odbc_result($rs,"CLIENT_NAME"); $backupname=odbc_result($rs,"BACKUP_NAME"); $start_time=odbc_result($rs,"BACKUP_START_TIME"); $end_time=odbc_result($rs,"BACKUP_END_TIME"); $remarks=odbc_result($rs,"REMARKS"); //echo "<table width=60% height=5% cellspacing='1' cellpadding='2' border='1'>"; echo "<tr>"; echo "<td align=center><small>$client</small></td>","\n"; echo "<td align=center><small>$backupname</small></td>","\n"; echo "<td align=center><small>$start_time</small></td>","\n"; echo "<td align=center><small>$end_time</small></td>","\n"; echo "<td align=center><small>$remarks</small></td>","\n"; echo "</tr>"; } echo "</table>"; edit: You forgot the } at the end of the while needs to be before ending the table. Quote Link to comment Share on other sites More sharing options...
Phpnewbie23 Posted January 12, 2009 Author Share Posted January 12, 2009 Cheers had the bracket in my original code but moving it where you suggested worked brilliantly cheers its taken me nearly all day to figure that one out. ;D ;D How would you do the colouring of the text for success or fail. Cheers Quote Link to comment Share on other sites More sharing options...
Phpnewbie23 Posted January 12, 2009 Author Share Posted January 12, 2009 Worked out how to change the font colour ;D ;D nows its just the UNIX time stamp. :o :o Cheers Quote Link to comment Share on other sites More sharing options...
ngreenwood6 Posted January 12, 2009 Share Posted January 12, 2009 I figured I would help with the unix timestamp. You can use this to convert the time $time = time(); //makes the timestamp $date = date("m/d/Y", $time); Quote Link to comment Share on other sites More sharing options...
Phpnewbie23 Posted January 13, 2009 Author Share Posted January 13, 2009 I am trying to work out how to get my time changed from UNIX to user readable time. $start_time=odbc_result($rs,"BACKUP_START_TIME"); $end_time=odbc_result($rs,"BACKUP_END_TIME"); The above gets the start and the end time from the database. The below code puts the data in a table along with other data. echo "<td align=center><small>$start_time</small></td>","\n"; echo "<td align=center><small>$end_time</small></td>","\n"; I was just after a little help on how to change the BACKUP_START_TIME also the BACKUP_END_TIME to a readable date format i have been looking at it for most of the day now ??? ??? ??? ??? Cheers Quote Link to comment Share on other sites More sharing options...
ngreenwood6 Posted January 13, 2009 Share Posted January 13, 2009 I am not sure what your question is. Did you look at the example that I gave you about the date() function? Quote Link to comment Share on other sites More sharing options...
Phpnewbie23 Posted January 13, 2009 Author Share Posted January 13, 2009 Sorry. I dont understand your example or are we on the 2 seperate paths. I already have the time stamps which are populated by the database the start time BACKUP_START_TIME and the end time BACKUP_END_TIME "see image attached" And instead of: Start time End Time 1227142806 1227147684 I planned to have: Start Time End Time Thursday, November 20th 2008, 1:00:06 (GMT) Thursday, November 20th 2008, 2:21:24 (GMT) or maybe trimmed down abit. Cheers [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
ngreenwood6 Posted January 13, 2009 Share Posted January 13, 2009 I do not use odbc so I am confused as to how that works but to convert a timestamp to a date you need to use the php date() function. For example if the $start_time and $end_time in this code: echo "<td align=center><small>$start_time</small></td>","\n"; echo "<td align=center><small>$end_time</small></td>","\n"; give you the timestamp then you would change the code to this: echo "<td align=center><small>" . date("m/d/Y", $start_time) . "</small></td>","\n"; echo "<td align=center><small>" . date("m/d/Y", $end_time) . "</small></td>","\n"; Which would then make it a date like 01/13/09(January 13 2009). You can check out this site for other examples http://www.tizag.com/phpT/phpdate.php of how to format the date Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.