Need to make a table like this with PHP:

<table>
<tr>
<td>image1</td>
<td>image2</td>
<td>image3</td>
<td>image4</td>
</tr>
<tr>
<td>link1</td>
<td>link2</td>
<td>link3</td>
<td>link4</td>
</tr>
<tr>
<td>image5</td>
<td>image6</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>link5</td>
<td>link6</td>
<td> </td>
<td> </td>
</tr>
</table>

Anyone?

    Unless you were say retrieving the contents of the table from a database, you might as well hardcode the form instead of suffering the overhead that comes with PHP.

      It should list all files with a certain condition (filename) in a dir, with a link in the td under it, as in the table example.

        I know how to retrieve the filenames, that was not my question.

        My question:

        How to write this table with PHP:

        <table>
        <tr>
        <td>image1</td>
        <td>image2</td>
        <td>image3</td>
        <td>image4</td>
        </tr>
        <tr>
        <td>link1</td>
        <td>link2</td>
        <td>link3</td>
        <td>link4</td>
        </tr>
        <tr>
        <td>image5</td>
        <td>image6</td>
        <td> </td>
        <td> </td>
        </tr>
        <tr>
        <td>link5</td>
        <td>link6</td>
        <td> </td>
        <td> </td>
        </tr>
        </table>

          I know how to retrieve the filenames, I need to know the code to write the above table.

          You have given the HTML code yourself.

          No one can/should give you the code in PHP because
          a) your requirements listed are not complete,
          b) you should attempt to solve this yourself before asking.

          Conversely, I could be cynical and just do an echo or heredoc of the code you provided, but I doubt that will help you at all.

            This is what I have:

            $id = $_SESSION['id'];
            $path = "a/";
            $img = $path . $id . "_" . "*" . ".jpg";
            $un = "?" . time();
            $count = 0;
            $count2 = 0;
            echo "<table cellpadding=\"0\" cellspacing=\"5\"><tr>";
            foreach (glob("$img", GLOB_BRACE) as $image) {
            if(!@getimagesize($image)){
            msgs($lang, 21, $msg_go);
            } else {
            $count++;
            list($w, $h) = getimagesize($image);
            $image2 = str_replace('a/', 's/', $image);
            $image3 = str_replace('a/', '', $image);
            
            echo "<td class=\"td2\" align=\"center\">";
            echo "<img src=\"$image2" . "$un\" border=\"0\" onClick=\"MM_openBrWindow('showpic.php?img=$image3','','status=yes, width=$w, height=$h')\">";
            echo "</td>";
            
            	if($count == 6){
            	echo "</tr><tr>";
            
            	foreach (glob("$img", GLOB_BRACE) as $image) {
            	$image4 = str_replace('a/', '', $image);
            	$count2++;
            		echo "<td class=\"td2\" align=\"center\">";
            		echo "<a href=\"?replace=$image4\"><img src=\"../gfx/rep.gif\" width=\"12\" height=\"12\" border=\"0\"></a>  <a href=\"#\" onClick=\"confirmDelete('$image4');return false;\"><img src=\"../gfx/del.gif\" width=\"12\" height=\"12\" border=\"0\"></a>";
            		echo "</td>";
            
            		if($count2 == 6){
            		echo "</tr><tr>";
            
            		}
            		}
            
            		} if($count == 6){
            	echo "</tr><tr>";
            	}
            	}
            } 
            
            
            echo "</tr></table>";

              For other people who are trying to learn how to write HTML tables with PHP. This is basic code for writing a table with 2 rows and 8 colums:

              <table border=1>
              <tr>
              <? for($i = 1; $i < 9; $i++) { ?>
              <td align="center">
              <? echo $i; ?>
              <? } ?>

              </tr><tr>

              <? for($i = 1; $i < 9; $i++) { ?>
              <td align="center">hello</td>
              <? } ?>	

              </tr>
              </table>

              I hope someone can help me write the code that I need too.

                basically what you are saying is that you want to go four colums across for as many rows as you need?

                <?php
                
                $cols = 4;
                $arrayofitems = Array('a','b','c','d','e','f','g','h','i');
                $rows = ceil(sizeof($arrayofitems) / $cols);
                $counter = 0;
                
                echo '<table border=1 cellpadding=5>';
                
                for($i = 0; $i < $rows; $i++) {
                
                echo '<tr>';
                
                for($j = 0; $j < $cols; $j++) {
                
                	if(!empty($arrayofitems[$counter])) {
                
                		echo '<td>Column '.$arrayofitems[$counter].'</td>';
                	}
                	else {
                
                		echo '<td>&nbsp;</td>';
                	}
                
                	$counter++;
                }
                
                echo '</tr>';
                }
                
                echo '</table>';
                
                ?>

                  I need:

                  4 rows across
                  4 rows across

                  4 rows across
                  4 rows across

                  4 rows across
                  4 rows across

                  Until all results are displayed...

                  So in HTML:

                  <table>
                  <tr>
                  <td>image1</td>
                  <td>image2</td>
                  <td>image3</td>
                  <td>image4</td>
                  </tr>
                  <tr>
                  <td>link1</td>
                  <td>link2</td>
                  <td>link3</td>
                  <td>link4</td>
                  </tr>
                  <tr>
                  <td>image5</td>
                  <td>image6</td>
                  <td> </td>
                  <td> </td>
                  </tr>
                  <tr>
                  <td>link5</td>
                  <td>link6</td>
                  <td> </td>
                  <td> </td>
                  </tr>
                  </table>

                    Modify the code which I posted to display two rows, I've written you a very easy to understand example, please try and help yourself.

                    Andrew

                      I have tried and tried and can't seem to work it out, that's why I posted this question on this forum.

                      If it's so easy for all of you, why not give me the code so I learn from that?

                        I've given you the code for single row multiple columns, you will never learn anything unless you try.

                        I've pasted the code here because for as long as you refuse to learn I will continue to be able to afford the life I've become acustomed.

                        Don't take this as arrogance or bad manners but there are a lot of really high quality developers here who get fed up of answering the same question a million times by people who refuse to give it a go. I've posted some really easy to follow PHP that you could have modified, had you attempted to modfiy the code then got stuck, loads of people would have chipped in to help.

                        I suppose you've got your way because I've posted. Hey Ho.

                        It's really not difficult if you read and think, PHP is such as easy to use language, it eats these kind of things up for breakfast.

                        <?php
                        
                        $cols = 4;
                        $arrayofitems = Array('a','b','c','d','e','f','g','h','i');
                        $arrayofitems2 = Array('description of a','description of b','description of c','description of d','description of e','description of f','description of g','description of h','description of i');
                        $rows = ceil(sizeof($arrayofitems) / $cols);
                        $counter = 0;
                        
                        $content = '<table border=1 cellpadding=5>';
                        
                        for($i = 0; $i < $rows; $i++) {
                        
                        $content .= '<tr>';
                        
                        for($j = 0; $j < $cols; $j++) {
                        
                        	if(!empty($arrayofitems[$counter])) {
                        
                        		$content .= '<td align="center"><strong>'.$arrayofitems[$counter].'</strong></td>';
                        	}
                        	else {
                        
                        		$content .= '<td>&nbsp;</td>';
                        	}
                        
                        	$counter++;
                        }
                        
                        $content .= '</tr>';
                        
                        $counter = $counter - $cols;
                        
                        $content .= '<tr>';
                        
                        for($j = 0; $j < $cols; $j++) {
                        
                        	if(!empty($arrayofitems[$counter])) {
                        
                        		$content .= '<td>Column '.$arrayofitems2[$counter].'</td>';
                        	}
                        	else {
                        
                        		$content .= '<td>&nbsp;</td>';
                        	}
                        
                        	$counter++;
                        }
                        
                        $content .= '</tr>';
                        }
                        
                        ?>
                        

                        Will produce

                        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
                        <html xmlns="http://www.w3.org/1999/xhtml">
                          <head>
                            <title></title>
                          </head>
                          <body>
                            <table border="1" cellpadding="5">
                              <tr>
                                <td align="center">
                                  <strong>a</strong>
                                </td>
                                <td align="center">
                                  <strong>b</strong>
                                </td>
                                <td align="center">
                                  <strong>c</strong>
                                </td>
                                <td align="center">
                                  <strong>d</strong>
                                </td>
                              </tr>
                              <tr>
                                <td>
                                  Column description of a
                                </td>
                                <td>
                                  Column description of b
                                </td>
                                <td>
                                  Column description of c
                                </td>
                                <td>
                                  Column description of d
                                </td>
                              </tr>
                              <tr>
                                <td align="center">
                                  <strong>e</strong>
                                </td>
                                <td align="center">
                                  <strong>f</strong>
                                </td>
                                <td align="center">
                                  <strong>g</strong>
                                </td>
                                <td align="center">
                                  <strong>h</strong>
                                </td>
                              </tr>
                              <tr>
                                <td>
                                  Column description of e
                                </td>
                                <td>
                                  Column description of f
                                </td>
                                <td>
                                  Column description of g
                                </td>
                                <td>
                                  Column description of h
                                </td>
                              </tr>
                              <tr>
                                <td align="center">
                                  <strong>i</strong>
                                </td>
                                <td>
                                  &nbsp;
                                </td>
                                <td>
                                  &nbsp;
                                </td>
                                <td>
                                  &nbsp;
                                </td>
                              </tr>
                              <tr>
                                <td>
                                  Column description of i
                                </td>
                                <td>
                                  &nbsp;
                                </td>
                                <td>
                                  &nbsp;
                                </td>
                                <td>
                                  &nbsp;
                                </td>
                              </tr>
                            </table>
                          </body>
                        </html>
                        

                          1/ I didn't refuse to give it a go, and I don't refuse to learn, I'm just not that smart in the math department. But hey, I'm good at other stuff, so no need to degrade me.

                          2/ I'm not a high quality programmer, I'm a novice (started 2 weeks ago), and you gotta start somewhere... This IS an open forum for all, and you don't HAVE to answer...

                          3/ I found code similar to the one you posted before, and didn't manage to get it to work for my purpose, not even after 2 days of trying.

                          4/ I posted the code that I created myself. It took me 3 days to build it, so I think I showed I was trying, and you can read in this post what kindof help I got.

                          Why do you all have to be so nasty? Jeez... If you're not planning to help a person, just say so using normal language, or don't say anything at all...

                          I do want to thank you for posting your last code, even if it was for you to 'continue to be able to afford the life you've become accustomed to as long as I refuse to learn'. It's a very elegant way of saying I'm stupid. Do all programmers feel so superior?

                          Now let's hope some Indian or Chinese programmer doesn't take your job... See, I can be nasty too.

                          I would suggest that PHPBuilder creates a forum for high-quality programmers ONLY where novices are kicked off right away by moderators and/or senior members, so the 'real' programmers can continue their business, and maybe PHPBuilder could create a PHP 101 with code snippets that are requested a million times by novices such as me...

                          I won't use this forum ever again, thx, I'm sure you're happy now.

                            wow.. someone really pissed off.
                            calm down.
                            it's only php 🙂

                              Mike, really, please grow up.

                              I'm not a high quality programmer, I'm a novice (started 2 weeks ago), and you gotta start somewhere... This IS an open forum for all, and you don't HAVE to answer...

                              Registered: Nov 2003
                              Location:
                              Posts: 29

                              Oh, and your 1st post: 03-28-2004 12:17 PM

                              So, unless you found the magical supermagnetic black hole means of traveling the speed of light, this adds up to something a little longer than 2 weeks ago. You're apparently more of a math wizard than you think.

                              Try taking a look around the PHPBuilder site, and you will find code snippets all over. Here in the forums, and in the snippet library.

                              No offense, but if it took you 3 days to write this, then maybe it's time to consider a new profession... because this really has nothing to do with math wizardry.

                              <table border=1> 
                              <tr> 
                              <? for($i = 1; $i < 9; $i++) { ?> 
                              <td align="center"> 
                              <? echo $i; ?> 
                              <? } ?> 
                              
                              </tr><tr> 
                              
                              <? for($i = 1; $i < 9; $i++) { ?> 
                              <td align="center">hello</td> 
                              <? } ?> 
                              
                              </tr> 
                              </table> 
                              

                                I know someone was going to say that... Yes, I'm guilty, I looked into PHP before, you should become a detective instead of a programmer... remember this when you're being outsourced.

                                I really started to work with PHP 2 weeks ago, as I said. Adding bible quotes to your posts doesn't make you god...

                                It took me 3 days to make this code (not the code you highlighted) as part of an application that resizes, thumbnails and displays images. I wrote it from scratch, because I DO try to learn:

                                
                                $id = $_SESSION['id']; 
                                $path = "a/"; 
                                $img = $path . $id . "_" . "*" . ".jpg"; 
                                $un = "?" . time(); 
                                $count = 0; 
                                $count2 = 0; 
                                echo "<table cellpadding=\"0\" cellspacing=\"5\"><tr>"; 
                                foreach (glob("$img", GLOB_BRACE) as $image) { 
                                if(!@getimagesize($image)){ 
                                msgs($lang, 21, $msg_go); 
                                } else { 
                                $count++; 
                                list($w, $h) = getimagesize($image); 
                                $image2 = str_replace('a/', 's/', $image); 
                                $image3 = str_replace('a/', '', $image); 
                                
                                echo "<td class=\"td2\" align=\"center\">"; 
                                echo "<img src=\"$image2" . "$un\" border=\"0\" onClick=\"MM_openBrWindow('showpic.php?img=$image3','','status=yes, width=$w, height=$h')\">"; 
                                echo "</td>"; 
                                
                                    if($count == 6){ 
                                    echo "</tr><tr>"; 
                                
                                    foreach (glob("$img", GLOB_BRACE) as $image) { 
                                    $image4 = str_replace('a/', '', $image); 
                                    $count2++; 
                                        echo "<td class=\"td2\" align=\"center\">"; 
                                        echo "<a href=\"?replace=$image4\"><img src=\"../gfx/rep.gif\" width=\"12\" height=\"12\" border=\"0\"></a>  <a href=\"#\" onClick=\"confirmDelete('$image4');return false;\"><img src=\"../gfx/del.gif\" width=\"12\" height=\"12\" border=\"0\"></a>"; 
                                        echo "</td>"; 
                                
                                        if($count2 == 6){ 
                                        echo "</tr><tr>"; 
                                
                                        } 
                                        } 
                                
                                        } if($count == 6){ 
                                    echo "</tr><tr>"; 
                                    } 
                                    } 
                                   }  
                                
                                
                                echo "</tr></table>";   

                                But I'm sure you're gonna say something else degrading now... seems most programmers DO have no people skills...

                                  So coming on here and flaming the people trying to help you is the solution?!? (Myself not included. I admittedly have no intention of helping you)

                                  It's sad if you believe everyone's jobs are being outsourced so much. You must've been recently outsourced or are getting ready to be. The trick is to put yourself into a position to be indisposable and to get your mitts into many many pots (without overextending of course). Tat's not that hard to do as a programmer, and even easier for me since I am a CIO and not just a programmer anyhow. But hey, I can respect your fear of outsourcing. I just don't fear it myself. (Oh, and some well timed and well placed investments are doing just fine to keep me well off if I ever decide to retire.) You fear the future too much. Plan better and you won't have to.

                                  Anyhow, I'm not addressing this post anymore. Good luck to you Mike.

                                  (Oh, and I don't pretend to be God, or claim to be. I don't quite know where in my post I ever said I was. That would be blasphemous.)

                                    I don't take any sides here but:

                                    The trick is to put yourself into a position to be indisposable

                                    You mean by writing code noone else will understand?
                                    By not commenting anything you do?

                                    Anyone is disposable if the code is written in such a manner that anyone can quickly understand and extend it.

                                    If the opposite is true, then sure, that makes you indisposable, but also a bad programmer. If you die in a car crash, what happens to your customers? They are stuck with a project that will cost them more to extend than re-write from scratch.

                                    Sometimes even the best programmer can get stuck on the easiest thing, give them a break.

                                    P.S There is no trick to make yourself indisposable. You can do that easily by being good at what you do.

                                      WE can all write, but how many of us could write a book worth publishing?

                                      We could all learn a musical instrument, but how many of us would ever be good enough to play in a major orchestra?

                                      Anyone can learn a programming language, but not 1 in 10 could ever write one that is any good. And it is that that makes nasty people like me and The Defender indispensable.

                                      So, we don't mind helping the noobs out, because most will never be a threat. But we don't intend to write your code for you: especially as half of it ends up on other peoples sites that they have been paid to produce.

                                      What the odlbies post here is to help you solve your own problems. So, it's untested, uncommented, and (mine at least) is full of typos. Working out what it does is how YOU will learn; and 'working-out' with your problems is how I learn, 🆒