Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: while() help

  1. #1
    New Coder
    Join Date
    Jul 2006
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    while() help

    I have a table generated from a mysql table. One of the fields in the table has urls of images. I want the generated html table show the image instead of just the url how would I go about this. Here is my code:
    PHP Code:
    while($rows mysql_fetch_array($resultMYSQL_ASSOC)) {
            echo 
    '<tr>';
            foreach(
    $rows as $data) {
                echo 
    '<td>'.$data.'</td>';
            }
        } 

  • #2
    Regular Coder
    Join Date
    Jan 2006
    Posts
    189
    Thanks
    1
    Thanked 0 Times in 0 Posts
    PHP Code:
    <?while($rows mysql_fetch_array($resultMYSQL_ASSOC)) {
            echo 
    '<tr>';
            foreach(
    $rows as $data) {
                echo 
    '<td><img src=\"$data\"></td>';
            }
        }  
    ?>
    That should work.. i think?

  • #3
    New Coder
    Join Date
    Jul 2006
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts
    nevermind i figured it out. I needed to use an if statement with a regular expression to find that its a image url.

    So it looks like this:
    PHP Code:
    while($rows mysql_fetch_array($resultMYSQL_ASSOC)) {
            echo 
    '<tr>';
            foreach(
    $rows as $data) {
                if(
    ereg("^\/images"$data)) {
                    echo 
    '<td><img src="/phptest/user'.$data.'"></td>';
                }else{
                    echo 
    '<td>'.$data.'</td>';
                }    
            }
            
        } 


  •  

    Posting Permissions

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