how to echo results into column counts ?

Discussion in 'PHP' started by pixmania, Apr 24, 2009.

  1. #1
    Anyone any hints how I echo my results into a column array, I'm trying to print say 4 results then <br> for new line... column

    <?php
    $path = "../templates/";
    $dh = opendir($path);
    $i=1;
    while (($file = readdir($dh)) !== false) {
        if($file != "." && $file != "..") {
            echo "<img src='../templates/$file/$file.gif'> <button class='buttonclass' type='submit' name='file' value='$file'>Change - $file</button>";
            $i++;
        }
    }
    closedir($dh);
    ?>
    PHP:

     
    pixmania, Apr 24, 2009 IP
  2. JamesColin

    JamesColin Prominent Member

    Messages:
    7,874
    Likes Received:
    164
    Best Answers:
    1
    Trophy Points:
    395
    Digital Goods:
    1
    #2
    what is a column array?
    do you mean a html table?
     
    JamesColin, Apr 24, 2009 IP
  3. pixmania

    pixmania Peon

    Messages:
    229
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    probable :D

    Yeah <td>echo 4 results</td> then <br or tr> I guess

    4 across and whatever amount the results reveal down
     
    pixmania, Apr 24, 2009 IP
  4. bozghiyy

    bozghiyy Peon

    Messages:
    19
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    sory i did not understand exactly i try to make it now
     
    bozghiyy, Apr 24, 2009 IP
  5. pixmania

    pixmania Peon

    Messages:
    229
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I have this result from the script above
    [​IMG]

    I'm trying to get this type of result
    [​IMG]

    4 results across then <br>
    another 4 across and <br> etc..
     
    pixmania, Apr 24, 2009 IP
  6. bozghiyy

    bozghiyy Peon

    Messages:
    19
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    
    <?php
    $path = "../templates/";
    $dh = opendir($path);
    $i=0;
    echo '<table border="1">';
    while (($file = readdir($dh)) !== false) {
        if($file != "." && $file != "..") {
    	if(is_int($i/4) || $i == 0) echo '<tr>';
            echo "<td><img src='../templates/$file/$file.gif'> <button class='buttonclass' type='submit' name='file' value='$file'>Change - $file</button></td>";
       	if(is_int(($i-3)/4)) echo '</tr>';    
    		$i++;
        }
    }
    echo '</table>';
    closedir($dh);
    ?>
    
    PHP:
    this outpust
    <table>
    <tr>
    <td>1</td>
    <td>2</td>
    <td>3</td>
    <td>4</td>
    </tr>
    <tr>
    <td>5</td>
    <td>6</td>
    <td>7</td>
    <td>8</td>
    </tr>
    ....
    </table>

    This is just a simple <br> after 4 on the row
     <?php
    $path = "../templates/";
    $dh = opendir($path);
    $i=0;
    
    while (($file = readdir($dh)) !== false) {
        if($file != "." && $file != "..") {
    
            echo "<img src='../templates/$file/$file.gif'> <button class='buttonclass' type='submit' name='file' value='$file'>Change - $file</button>";
       	if(is_int(($i-3)/4)) echo '</br>';    
    		$i++;
        }
    }
    echo '</table>';
    closedir($dh);
    ?>
    
    PHP:
     
    bozghiyy, Apr 24, 2009 IP
  7. JamesColin

    JamesColin Prominent Member

    Messages:
    7,874
    Likes Received:
    164
    Best Answers:
    1
    Trophy Points:
    395
    Digital Goods:
    1
    #7
    <?php
    $path = "../templates/";
    $dh = opendir($path);
    $i=1;
    echo "<table>";
    while (($file = readdir($dh)) !== false) {
        if($file != "." && $file != "..") {
            echo "<tr><td><img src='../templates/$file/$file.gif'></td><td><button class='buttonclass' type='submit' name='file' value='$file'>Change - $file</button></td></tr>";
            $i++;
        }
    }
    echo  "</table>";
    closedir($dh);
    ?>
    PHP:
    this way it constructs a table with 2 columns, one with the image and the other with the button.

    edit: ok I didn't see the new messages, i didn't understand what you wanted. now you have the solution.
     
    JamesColin, Apr 24, 2009 IP
  8. bozy12v

    bozy12v Active Member

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #8
    
    <?php
    include('connex.php');
    echo "<table class='later' border=0>";
    	$result = mysql_query("SELECT * FROM joace ORDER BY vot DESC LIMIT 40");
    $columns=4;
    	for ($i=0;$i<mysql_num_rows($result);$i=$i+1)
    {
    if($i % $columns == 0) {
    echo "</tr><tr>"; }
    $nume=mysql_result($result,$i,nume);
    echo $nume;
    echo "</td>";
     
    }
    	 mysql_close($conex);
    	echo  "</tr></table>";
    	?>
        
    PHP:
     
    bozy12v, Apr 24, 2009 IP
  9. pixmania

    pixmania Peon

    Messages:
    229
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Perfect thanks very much rep+ cheers
     
    pixmania, Apr 24, 2009 IP