Results 1 to 3 of 3

Thread: foreach problem very strange...[RESOLVED]

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2003
    Location
    In Front of my computer...
    Posts
    367

    Resolved foreach problem very strange...[RESOLVED]

    Code...
    PHP Code:
    echo "<table>";
        foreach(
    $output as $val)
        {
        echo    
    "<tr>";
        echo    
    "<td>";
        echo 
    $val;
        echo    
    "</td>";
        echo    
    "</tr>";
        }
    echo    
    "</table>"
    well i want each array value to be like this...in their own cell
    Code:
    <table>
    <tr>
    <td>
    *value here*
    </td>
    </tr>
    <tr>
    <td>
    *next value*
    ...
    ...
    ...so on
    and with the code above it is supposed to do that!...guess what, It DOESNT!

    it creates a new table a tr a td for each value so i end up having tons of tables :/

    anyone knows what's wrong with it ?...
    Thanks!

    many thanks to visualad he corrected me...
    THREAD RESOLVED!
    Last edited by EJ12N; Apr 16th, 2005 at 04:55 PM.
    Born to help others
    (If I've been helpful then please rate my post. Thanks)

    call me EJ or be slapped!

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: foreach problem very strange...

    Can you post the exact ouput from the View Source in your browser?? There doesn't appear to be anything wrong with it. To make it more readable you should embed the PHP inside the HTML, not the other way round:
    PHP Code:
    ?>
    <table>
        <?php foreach($output as $val): ?>
            <tr>
                <td><?php echo($val?></td>
            </tr>
        <?php endforeach; ?>
    </table>
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2003
    Location
    In Front of my computer...
    Posts
    367

    Re: foreach problem very strange...

    <table><tr><td>TXT</td></tr><tr><td>TXT2</td></tr></table>
    <table><tr><td>txt3</td></tr><tr><td>txt4</td></tr></table>
    and so on...
    also tried this...

    echo "<table>";
    foreach($output as $val)
    {
    echo "<tr><td>".htmlspecialchars($val)."</td></tr>";
    }
    echo "</table>";
    nothing...
    Born to help others
    (If I've been helpful then please rate my post. Thanks)

    call me EJ or be slapped!

Posting Permissions

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



Click Here to Expand Forum to Full Width