Current location: Hot Scripts Forums » Programming Languages » PHP » [SOLVED] Fuction in a loop generated from an array


Fuction in a loop generated from an array

Closed Thread
  #1 (permalink)  
Old 02-12-10, 08:28 AM
lavochkin's Avatar
lavochkin lavochkin is offline
Newbie Coder
 
Join Date: Jan 2010
Location: Boulder City , NV
Posts: 13
Thanks: 3
Thanked 0 Times in 0 Posts
Fuction in a loop generated from an array

Ok,here is my array:

PHP Code:

$tableColumns 'Flight Nr,Date,Company,From,To,PAX,Aircraft,Landing<br> Speed,Landing<br> Pitch,Landing<br>Vert Speed,Flight<br>Time,Dist.<br>Nm,Cargo<br>Lbs,Result, ';


$dataFields =     'ranklabel($TFT),FlightId,FlightDate,CompanyName,DepartureIcaoName,ArrivalIcaoName,NbrPassengers,AircraftName,LandingSpeed,LandingPitch,TouchDownVertSpeedFt,TotalBlockTime,TotalDistance,CargoWeight,FlightResult,';

$pilotFields =     'Rank,PilotName,TnF,TNbrPassengers,AFuel,ATotalDistance,TCargoWeight,TotalPoint';
//$pilotFields =     'PilotName,TTotalBlockTime,TNbrPassengers,TBonusPoints,TPenalityPoints';
$VAColumns 'Rank,Pilot,Flights,PAX,Fuel<br>LBS,Dist.<br>Nm,Cargo<br>Lbs,Total Bonus Points'
Here is the the table:



PHP Code:

ListStart    ='<table width="'.$tableWidth.'" cellspacing="1" cellpadding="2" align="center" style="font: normal 11px/14px Arial,sans-serif;padding:2px 7px 2px 7px">';

$TDTitStyle ='<td nowrap style="background-color:#0080FF;color:white;padding:2px 5px 2px 5px">';
$TableVA ='<tr>';
    
// loop to create the column headers
    
for ($i=0;$i<count($PilotFieldNames);$i++)
    {
        
$TableVA .= $TDTitStyle.
        
' <a href="?action=va&s='.$PilotFieldNames[$i].'&d='.$sortOptions[$PilotFieldNames[$i]].'&p='.$p.'"
        style="text-decoration:none;color:white">'
.$VAcolumnNames[$i].'</a></td>'.chr(13);
    }
$TableTitle ='<tr>';
    
// loop to create the column headers
    
for ($i=0;$i<count($dbFieldNames);$i++)
    {
        
$TableTitle .= $TDTitStyle.
        
' <a href="?pilotflight='.$pilotflight.' &s='.$dbFieldNames[$i].'&d='.$sortOptions[$dbFieldNames[$i]].'&p='.$p.'"
        style="text-decoration:none;color:white">'
.$columnNames[$i].'</a></td>'.chr(13);
    }
$TDListOdd    ='<td nowrap style="background-color:#D5E4FD;color:black;padding-left:5px">';    // define here background and font colors of
$TDListEven    ='<td nowrap style="background-color:#7CADDE;color:black;padding-left:5px">';    // the alternating rows
$TRList        ='<tr>';
$ListStop    ='</table>'

Now How do get the results of a fuction to be displayed in this table uesing the array?

Does this make sense?

Thanks
Rick
  #2 (permalink)  
Old 02-12-10, 09:52 AM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
First set up some 'style'

Instead of this:

HTML Code:
<td nowrap style="background-color:#D5E4FD;color:black;padding-left:5px">
Use this:

HTML Code:
<style type="text/css">
td
{
color:black;
padding-left:5px;
wrap:none;  /* Look this up at [url=http://w3schools.com]W3Schools Online Web Tutorials[/url] - I'm not sure if wrap is valid*/
}
tr.odd
{
background-color:#D5E4FD;
}
tr.even
{
background-color:#fff;  /* Different value */
}
</style>
</head>
<body>
<table>
<tr class="odd">
<td>Stuff</td>
</tr>
<tr class="even">
<td>Suff2</td>
</tr>
</table>
</body>
This makes it easier to code and easier to maintain.
  #3 (permalink)  
Old 02-12-10, 11:28 AM
lavochkin's Avatar
lavochkin lavochkin is offline
Newbie Coder
 
Join Date: Jan 2010
Location: Boulder City , NV
Posts: 13
Thanks: 3
Thanked 0 Times in 0 Posts
Ok, Thanks for link.

Well wirehopper,

I may be trying to do something that is way over my understanding of PHP. First , I do not have a clue what most of this script means or does. The link you gave me is great, but I do not know where to start. This is not my code. I need some formal training on PHP code.

Any way, I think on this issue I need to go and request a script forum and just have someone do this for me.

Thanks again for your reply.

This thread is done.

Best Regards,
Rick Parkin
  #4 (permalink)  
Old 02-13-10, 05:09 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
Quote:
Now How do get the results of a fuction to be displayed in this table uesing the array?
PHP Code:

echo '<td>'.function($parameter).'</td>'
In the example above, function is the name of the function (you can't name functions function, it's a reserved word), and $parameter would be a value passed into the function. You can use the echo command to display the results, and the tds will put it in the table.

The reason I mentioned style is that it can be difficult to maintain code with a lot of inline style.
Closed Thread

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Array loop zerofill PHP 2 09-27-09 03:08 PM
Remove value from array Nikas PHP 1 05-20-09 03:20 AM
Multi-Dimensional Array Help Nikas PHP 17 05-04-09 02:10 AM
Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')' Dr. Forensics PHP 3 07-15-06 03:54 PM
linking to iframe not working :( j0d JavaScript 5 01-19-04 08:14 PM


All times are GMT -5. The time now is 08:10 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.