1
   

PHP help

 
 
mendoz
 
Reply Sun 24 Sep, 2006 04:18 pm
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
  • Topic Stats
  • Top Replies
  • Link to this Topic
Type: Discussion • Score: 1 • Views: 1,639 • Replies: 0
No top replies

 
 

Related Topics

Webdevelopment and hosting - Question by harisit2005
Showing an Ico File - Discussion by Brandon9000
how to earn money in internet - Discussion by rizwanaraj
The version 10 bug. Worse then Y2K! - Discussion by Nick Ashley
CSS Border style colors - Question by meesa
There is no Wisdom in Crowds - Discussion by ebrown p
THANK YOU CRAVEN AND NICK!!! - Discussion by dagmaraka
I'm the developer - Discussion by Nick Ashley
 
  1. Forums
  2. » PHP help
Copyright © 2024 MadLab, LLC :: Terms of Service :: Privacy Policy :: Page generated in 0.03 seconds on 05/09/2024 at 07:02:06