Greetings,
I'm looking to create a page which shows up to 6 tables at a time.
My idea was to make a page called 'tables.php' with a table in it with two rows and three columns,
inside every cell I'll put an <? include ('table.php'); ?>.
'tables.php' will connect to a specific database via a var ('tables.php?cat=cat1').
Then I want it to check how many rows are in that database.
I want up to 6 <? include ('table.php'); ?>. in a page.
So, if for example I have 10 rows in database 'cat1',
First page will have:
6 <? include ('table.php'); ?>,
Second page will have:
4 <? include ('table.php'); ?>,
2 <? include ('table-no.php'); ?>,
example:
'tables.php?cat=cat1?id=0':
[table][tr]
[td]<? include ('table.php'); ?>,[/td]
[td]<? include ('table.php'); ?>,[/td]
[td]<? include ('table.php'); ?>,[/td]
[/tr]
[tr]
[td]<? include ('table.php'); ?>,[/td]
[td]<? include ('table.php'); ?>,[/td]
[td]<? include ('table.php'); ?>,[/td]
[/tr]
[/table]
next
'tables.php?cat=cat1?id=1':
[table]
[tr]
[td]<? include ('table.php'); ?>,[/td]
[td]<? include ('table.php'); ?>,[/td]
[td]<? include ('table.php'); ?>,[/td]
[/tr]
[tr]
[td]<? include ('table.php'); ?>,[/td]
[td]<? include ('table-no.php'); ?>,[/td]
[td]<? include ('table-no.php'); ?>,[/td]
[/tr]
[/table]
previous
This is a code I got from another forum, and it shows pictures..
How can I modify it to my needs?
<?php
mysql_connect( "localhost", "username", "password" ); // Use correct stuff there
mysql_select_db( "images" ); // Use Database Name
$max_images = 6;
if( !isset( $_GET[ 'page' ] ) ) {
$page = 1;
}
else {
$page = $_GET[ 'page' ];
}
$from = ($page * $max_images) - $max_images;
// select the image url's from the db, i_id = the id of the row in the mysql db
$sql = "SELECT * FROM images ORDER BY i_id LIMIT $from, $max_images";
$s = mysql_query( $sql );
while( $res = mysql_fetch_array( $s ) ) {
$i = 1;
//example variables, might be different for you
// assuming the row name is "src"
$src = $res[ 'src' ];
echo '<img src="'.$src.'"> ';
if( $i > 4 ) {
echo '<br />';
}
$i++;
}
echo '<br />';
$total_images = mysql_result( mysql_query( "SELECT COUNT( i_id ) as Num FROM images" ), 0 );
$total_pages = ceil( $total_images / $max_images );
// previous page
if($page > 1){
$prev = ( $page - 1 );
echo '<a href="images.php?page='.$prev.'">Previous</a> ';
}
for( $i = 1; $i <= $total_pages; $i++ ) {
if( ( $page ) == $i ) {
echo "$i ";
}
else {
echo '<a href="images.php?page='.$i.'">$i</a> ';
}
}
// next page
if( $page < $total_pages ) {
$next = ( $page + 1 );
echo '<a href="images.php?page='.$next.'">Next</a>';
}
?>