SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    964
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    acending records in a array...

    How do I make this easier...

    Code:
    <td>number 1</td>
    <td>number 2</td>
    <td>number 3</td>
    <td>number 4</td>
    ...
    Could this be done in some sort of array??

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,135
    Mentioned
    16 Post(s)
    Tagged
    3 Thread(s)
    PHP Code:
    $rows = array(1,2,3,4);
    foreach(
    $rows as $row) echo '<td>number ',$row,'</td>',"\n"

  3. #3
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    964
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, but what if it looks like this?

    Code:
    <td>'.$numb1.'</td>
    <td>'.$numb2.'</td>
    <td>'.$numb3.'</td>
    <td>'.$numb4.'</td>
    ...

  4. #4
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    for($i 1; isset($numb{$i}); $i++){
        
    printf('<td>%s</td>'$numb{$i});

    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?
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  5. #5
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    964
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is there a way to do this...

    PHP Code:
    $rows = array(1,2,3,4);
    $rows2 = array(a,b,c,d);
    foreach(
    $rows as $row || $rows1 as $row2
    The above doesn't work?

  6. #6
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    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.

  7. #7
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    964
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    echo 'Test '.$row.'<input name="test'.$row2.'" class="style1" value="">'

  8. #8
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php
    $aPrimary 
    range(110);
    $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.

  9. #9
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    964
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Still 1 problem though... if secondary is like this:

    PHP Code:
    'Test %s<input name="'.test%s.'" class="style1" value=""> 
    I get an error... How do I get the "%s" into an "'.test%s.'"???


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •