Jump to content

Tables (rows and colums) with PHP


demetri

Recommended Posts

hi guys.. so I got this picture galleri with intergrated pagination. wouw.. its working and im sooo happy.. !! :) look here:

[url=http://gb2625.web05.talkactive.net/foto_base/contents.php]http://gb2625.web05.talkactive.net/foto_base/contents.php[/url]

okey, so everything is great! i just got this one wish.. it could be soo nice to have the pictures which are shown on the page to be kinda organized in rows and colums.. like maybe 5 rows and maybe 4 colums.. but I've seriously NO idear how to fix that !

maybe if some of u have some examples or tuts which I can use I would be very happy.. or maybe if u could even show the way to do it with my own code.. I appreciate any kind of help.. thanks!

[code]<?
include ("admin/dbpass.php");
$link = @mysql_connect ( "$host", "$user", "$passw" );
mysql_select_db ("$tab")
or exit ();

//pagination script1 begynder
if(!isset($_GET['page'])){
    $page = 1;
} else {
    $page = $_GET['page'];
}
$max_results = 2;
$from = (($page * $max_results) - $max_results); 
$sql = mysql_query("SELECT id, dayofmonth(datum), monthname(datum), year(datum), short, name, email, filename FROM pix_data order by datum desc, id desc LIMIT $from, $max_results");
while($tekst = mysql_fetch_array($sql)){
    //echo $tekst['name']."<br />";
echo "placeret " . $tekst[2] . " " . $tekst[1] . ", " . $tekst[3] . ", af: <a href=mailto:" . $tekst[6] . "> " . $tekst[5] . "</a><br><b>Kort beskrivelse:</b> " . $tekst[4] . "<br><a href=\"view_pic.php?id=" . $tekst[0] . "\" onclick=\"NewWindow(this.href,'picview','640','480','yes','center');return false\" onfocus=\"this.blur()\">Se billedet her!!</a><br><br><img src=" . $tekst[7] . " width= 150><br><br><br>";
}
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM pix_data"),0);
$total_pages = ceil($total_results / $max_results);
echo "<center>Vælg en side<br />";
if($page > 1){
    $prev = ($page - 1);
    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\"><<Previous</a> ";
}

for($i = 1; $i <= $total_pages; $i++){
    if(($page) == $i){
        echo "$i ";
        } else {
            echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> ";
    }
}

// Build Next Link
if($page < $total_pages){
    $next = ($page + 1);
    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">Next>></a>";
}
echo "</center>";
?> [/code]

Link to comment
https://forums.phpfreaks.com/topic/33334-tables-rows-and-colums-with-php/
Share on other sites

You can set up the page to show your records in a table pretty easliy. But, you would just set up the number of columns to display. The rows displayed would be determined by the number of records to be displayed on a page by setting $max_results appropriately. So, if you wanted to display your records in 5 rows and 4 columns, you just set you number of columns to 4 and $max_results to 20.

Just replace your while loop with this
[code]<?php
$maxColumns = 4; //You set this value
$currentColum = 1;

echo "<table>\n";

while($tekst = mysql_fetch_array($sql)){

    if ($currentColumn == 1) { echo "<tr>\n"; }
    echo "<td>\n";
    //echo $tekst['name']."<br />";
    echo "placeret " . $tekst[2] . " " . $tekst[1] . ", " . $tekst[3]
      . ", af: <a href=mailto:" . $tekst[6] . "> " . $tekst[5] . "</a><br>"
      . "<b>Kort beskrivelse:</b> " . $tekst[4] . "<br>"
      . "<a href=\"view_pic.php?id=" . $tekst[0] . "\""
      . " onclick=\"NewWindow(this.href,'picview','640','480','yes','center');return false\""
      . " onfocus=\"this.blur()\">Se billedet her!!</a><br>"
      . "<br><img src=" . $tekst[7] . " width= 150><br><br><br>";

    echo "</td>\n";
    $currentColum++
    if ($currentColumn > $maxColumns) {
        echo "</tr>\n";
        $currentColumn = 1;
    }
}
echo "</table>\n";
?>[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.