Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

generating table in a for loop inside a for loop

Status
Not open for further replies.

overflo

Technical User
Feb 10, 2003
70
AU
I'm trying to generate a table that displays a schedule. It calls two other functions (get_timeslot() & get_timetable()) These are working fine as it is displaying the correct data, just not inside the table. The table displays below it, only empty.
here is the code
function show_timetable() {
$returnStr = "<table width='90%' border='2' cellspacing='3' cellpadding='3'>
<tr>
<td width='24%'>Times</td>\n
<td width='11%'>Mon</td>\n
<td width='11%'>Tue</td>\n
<td width='11%'>Wed</td>\n
<td width='11%'>Thu</td>\n
<td width='11%'>Fri</td>\n
<td width='11%'>Sat</td>\n
</tr>";

for ($timeslot = 1; $timeslot < 10; $timeslot++) {
$returnStr .= '<tr>' . '<td>' . get_timeslot($timeslot) . '</td>';
for ($day = 1; $day < 7 ; $day++) {
$returnStr .= '<td>' . get_timetable($day, $timeslot) . '</td>';
}
$returnStr .= '</tr>' ;
}
$returnStr .= '</table>';
echo $returnStr;
}
 
overflo, sleipnir214,

I was just working on this example, I'm thinking that overlfo is "echoing or printing" the output of the functions.

overflo,
You want to use return when you use a function in this context.

Code:
<?php
$first_name = array('Matt','Susan','Mary');
$last_name = array('Jones','Smith','Williams');

function showNames($x){
global $first_name, $last_name;
return "{$first_name[$x]} {$last_name[$x]}";
}

$htmlStr = "<table><tr>
<td>Names</td></tr>
<tr>
<td>". showNames(2) ."</td></tr>
</table>";

echo $htmlStr;
?>


Thanks,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top