Hey there.
I'm having a difficulty with a php mysql script.
I need a page which shows only 6 pictures.
The adresses of the images are stored in a database.
let's say I have 10 images.
I want the first page to link to a new page with the remaining four images.
first page:
[image] [image] [image]
[image] [image] [image]
next
second page:
[image] [image] [image]
First page:
| include 'table.txt' | | include 'table.txt' | | include 'table.txt' |
| include 'table.txt' | | include 'no.txt' | | include 'no.txt' |
[image]
previous
Here is the code I got from another forum:
Code:<?php
mysql_connect( "localhost", "username", "password" ); // Use correct stuff there
mysql_select_db( "images" ); // Use Database Name
$max_images = 8;
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> ';
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>Previous</a> ';
}
for( $i = 1; $i <= $total_pages; $i++ ) {
if( ( $page ) == $i ) {
echo "$i ";
}
else {
echo '<a>$i</a> ';
}
}
// next page
if( $page </a>
Now, I don't want an image, I want an include.
The include is a table with variables (for the image and link) - table.txt.
I want only to show up to 6 includes in a page.
If there are no more includes I want to include 'soon.txt'
First page:
| include 'table.txt' | | include 'table.txt' | | include 'table.txt' |
| include 'table.txt' | | include 'table.txt' | | include 'table.txt' |
Second page:
| include 'table.txt' | | include 'table.txt' | | include 'table.txt' |
| include 'table.txt' | | include 'soon.txt' | | include 'soon.txt' |
Hope you undestood and could help,
Dror Wolmer