How do I make this easier...
Could this be done in some sort of array??Code:<td>number 1</td> <td>number 2</td> <td>number 3</td> <td>number 4</td> ...
| SitePoint Sponsor |




How do I make this easier...
Could this be done in some sort of array??Code:<td>number 1</td> <td>number 2</td> <td>number 3</td> <td>number 4</td> ...
PHP Code:$rows = array(1,2,3,4);
foreach($rows as $row) echo '<td>number ',$row,'</td>',"\n";




Thanks, but what if it looks like this?
Code:<td>'.$numb1.'</td> <td>'.$numb2.'</td> <td>'.$numb3.'</td> <td>'.$numb4.'</td> ...
But I can't really see what situation using table tags would be suitable. Is that just for layout or is it really tabular data?PHP Code:for($i = 1; isset($numb{$i}); $i++){
printf('<td>%s</td>', $numb{$i});
}
Jake Arkinstall
"Sometimes you don't need to reinvent the wheel;
Sometimes its enough to make that wheel more rounded"-Molona




Is there a way to do this...
The above doesn't work?PHP Code:$rows = array(1,2,3,4);
$rows2 = array(a,b,c,d);
foreach($rows as $row || $rows1 as $row2)
How exactly would you like 1, 2, 3, 4 and a, b, c, d be displayed?
@AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.




PHP Code:echo 'Test '.$row.'<input name="test'.$row2.'" class="style1" value="">';
?PHP Code:<?php
$aPrimary = range(1, 10);
$aSecondary = range('a', 'j');
for($iIndex = 0; $iIndex < 10; $iIndex++)
{
printf(
'Test %s<input name="test%s" class="style1" value="">',
$aPrimary[$iIndex],
$aSecondary[$iIndex]
);
}
/*
Test 1<input name="testa" class="style1" value="">
Test 2<input name="testb" class="style1" value="">
Test 3<input name="testc" class="style1" value="">
Test 4<input name="testd" class="style1" value="">
Test 5<input name="teste" class="style1" value="">
Test 6<input name="testf" class="style1" value="">
Test 7<input name="testg" class="style1" value="">
Test 8<input name="testh" class="style1" value="">
Test 9<input name="testi" class="style1" value="">
Test 10<input name="testj" class="style1" value="">
*/
?>
@AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.




Still 1 problem though... if secondary is like this:
I get an error... How do I get the "%s" into an "'.test%s.'"???PHP Code:'Test %s<input name="'.test%s.'" class="style1" value="">
Bookmarks