multi column output
Posted: Fri Sep 17, 2004 6:34 am
hey guys, I want to make a script that should disply info from $db in columns. Let's say 10 results / page.
i made a pagination script that display 10 results / page but in rows, not in columns. could you pls help me to modufy this script to be able to display info on 2 columns and on 5 rows.
Thx.
here is what I did.
i made a pagination script that display 10 results / page but in rows, not in columns. could you pls help me to modufy this script to be able to display info on 2 columns and on 5 rows.
Thx.
here is what I did.
Code: Select all
<?php
@include ('connect_to_db.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 pag
$max_results = 5;
/* Figure out the limit for the query based
on the current pag number. */
$from = (($pag * $max_results) - $max_results);
// Select the fields from the appropriate tables
$sql = "SELECT * FROM pics ORDER BY Id ASC LIMIT $from, $max_results";
$resursa = mysql_query($sql);
// Determine the number of records returned
$number = mysql_num_rows($resursa);
// Print the information
print "<table cellpadding='1' cellspacing='2' width='100%' border='0'>
<tr>
<td class='bg01' width='125' valign='middle'> <span class='scris1'>ID</span></td>
<td class='bg01' valign='middle'> <span class='scris1'>Picture name</span></td></tr>";
for($i=0; $i<$number; $i++) {
$id = mysql_result($resursa, $i, "id");
$nume = mysql_result($resursa, $i, "nume");
/* print even-numbered rows with diferent
background and create mouseeffect */
if ($i%2 == 0) {
print "<tr bgcolor='#dcdcdc' onMouseOver=this.bgColor='#ffe4b5' onMouseOut=this.bgColor='#dcdcdc'>";
} else {
print "<tr bgcolor='#dde7f5' onMouseOver=this.bgColor='#ffe4b5' onMouseOut=this.bgColor='#dde7f5'>";
}
print " <td width='125'> <span class='scris2'>$id</span></td>
<td> <span class='scris2'>$nume</span></td></tr>";
} // and if
print "</table>";
// Total number of results in db:
$total_results = mysql_result(mysql_query("SELECT COUNT(id) FROM pics"),0);
// Total number of pics.
$total_pics = ceil($total_results / $max_results);
// Close the database connection
mysql_close();
?>
<table align="center" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
<td width="50%" align="right">
<?php
// Previous
if($pag > 1){
$prev = ($pag - 1);
echo "<a href="".$_SERVER['PHP_SELF']."?pag=$prev" class='link2'>«</a> ";
}
// 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> ";
}
}
// Next
if($pag < $total_pics){
$next = ($pag + 1);
echo "<a href="".$_SERVER['PHP_SELF']."?pag=$next" class='link2'>» </a>";
}
?>
</td>
</tr>
</table>
?>