Page 1 of 1
Posted: Fri Sep 17, 2004 3:11 pm
by feyd
multi column output
Posted: Fri Sep 17, 2004 5:16 pm
by Think Pink
thx guys for all your explanations.
What do you think about thi? I found something in a tutorial and modified it a little.
Code: Select all
<?php
@include ('conectare.php');
// If current pag has a number, use it, if not, set one!
if(!isset($_GET['pag'])){
$pag = 1;
} else {
$pag = $_GET['pag'];
}
// Define the number of results per page and columns number
$max_results = 4;
$cols = 2;
/* Figure out the limit for the query based
on the current pag number. */
$from = (($pag * $max_results) - $max_results);
$query = "SELECT * FROM pics ORDER BY Id ASC LIMIT $from, $max_results";
$result = mysql_query($query);
$number = mysql_num_rows($result);
// start printing the info
echo "<table align='center' cellpadding='4' cellspacing='4' border='0'>";
//changed this to a for loop so we can use the number of rows
for($i = 0; $i < $number; $i++) {
$id = mysql_result($result, $i, "id");
$nume = mysql_result($result, $i, "nume");
if($i % $cols == 0) {
//if there is no remainder, we want to start a new row
echo "<TR bgColor='#dcdcdc'>";
echo "<TD onMouseOver=this.bgColor='#ffe4b5' onMouseOut=this.bgColor='#dcdcdc'>";
echo "<img src='uploads/$nume' border='0' alt=''></td>";
if(($i % $cols) == ($cols - 1) || ($i + 1) == $number) {
echo "</TR>";
}
}
echo "</table>";
// Figure out the total number of results in DB:
$total_results = mysql_result(mysql_query("SELECT COUNT(Id) FROM pics"),0);
// Figure out the total number of pics.
$total_pics = ceil($total_results / $max_results);
// Close the database connection
mysql_close();
// create next, previous links
echo "<table align='center' width='100' cellspacing='2' cellpadding='2' border='0'><tr><td>";
// previous
if($pag > 1){
$prev = ($pag - 1);
echo "<a href="".$_SERVER['PHP_SELF']."?pag=$prev" class='link2'>Previous</a> ";
}
echo "</td><td align='center'>";
// pag numbers
for($i = 1; $i <= $total_pics; $i++){
if(($pag) == $i){
echo "$i ";
}
else {
echo "<a href="".$_SERVER['PHP_SELF']."?pag=$i" class='link2'>$i</a> ";
}
}
echo "</td><td align='right'>";
// next
if($pag < $total_pics){
$next = ($pag + 1);
echo "<a href="".$_SERVER['PHP_SELF']."?pag=$next" class='link2'>Next </a>";
}
echo "</td></tr></table>";
?>
Thx again
Posted: Fri Sep 17, 2004 6:20 pm
by dethron
feyd proposed a better way to do that, look at the links stated above.