Jump to content

creation of image album website


MATLAB

Recommended Posts

I was not sure on which board to put this thread, so please move it if there is a more appropriate board.

 

I am wanting to create a website that displays images which I have put into a database. I would like the number of images on one page not to exceed 10, for example, and when the number of images in the database exceeds this number, a new page will be created. I would like it to function similar to Google Images where the number of pages is dictated by the number of images in the database.

 

I cant figure out how to achieve this, so any pointers or thoughts would be great :)

 

Thanks,

Matlab

Link to comment
Share on other sites

  • 2 weeks later...

Ok, so I have worked throug ha tutorial on basic pagination from phpfreaks website, built a database and started to design the page.

 

Im having a few problems displaying all of the fields from the database table. Certain fields just will not show in the page, for an unknown reason. I have made sure I have spelt them the same as how they are spelt in the database, but still, only some fields show up. Below is my code for the HTML, PHP and the structure of the database:

 

HTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Skydiving</title>
<link rel="stylesheet" type="text/css" href="stylesheet.css" />
<script type="text/javascript" src="scripts/jquery.js"></script>
<script type="text/javascript" src="scripts/psed.js"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="fancy_box/fancybox/jquery.mousewheel-3.0.2.pack.js"></script>
<script type="text/javascript" src="fancy_box/fancybox/jquery.fancybox-1.3.1.js"></script>
<script type="text/javascript" src="fancy_box/fancybox/fancy.js"></script>
<link rel="stylesheet" type="text/css" href="fancy_box/fancybox/jquery.fancybox-1.3.1.css" media="screen" />
</head>



<body>

<div id="main_container">

  <!--Header Content-->
  <div id="header_container">
      <a href="index.html"><img id="lgo" src="images/lgo.jpg" /></a>
      <div id="nav">
            <ul id='navlist'>
              <li><a href='index.html'>Home</a></li>
              <li><a href='contact.php'>Contact</a></li>
            </ul>
      </div>      
  </div>
  
  <!--Main content-->
    <div id="main_content_container">
    here is my videos<br />
    
    
        <?php include('scripts/display_vids.php');?>

<div class="push"></div>
</div>
<div class="push"></div>
<?php include('scripts/footer.php');?>
</body>
</html>


 

PHP (display_vids.php):

<?php

//Connect to the database
$user="USERNAME"; 
$password="PASSWORD";
$database="DATABASE";
$con = mysql_connect("localhost",$user,$password) or die ('Could not connect: ' . mysql_error());

mysql_select_db($database, $con);


// find out how many rows are in the table 
$sql = "SELECT  COUNT(id) FROM vids";
$result = mysql_query($sql, $con);
$r = mysql_fetch_row($result);
$numrows = $r[0];

// number of rows to show per page
$rowsperpage = 10;

// find out total pages
$totalpages = ceil($numrows / $rowsperpage);

// get the current page or set a default
if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
   // cast var as int
   $currentpage = (int) $_GET['currentpage'];
} else {
   $currentpage = 1;
}

// if current page is greater than total pages...
if ($currentpage > $totalpages) {
   // set current page to last page
   $currentpage = $totalpages;
} // end if
// if current page is less than first page...
if ($currentpage < 1) {
   // set current page to first page
   $currentpage = 1;
} 

// the offset of the list, based on current page 
$offset = ($currentpage - 1) * $rowsperpage;

// get the info from the db 
$sqql = "SELECT * FROM vids LIMIT $offset, $rowsperpage";
$result = mysql_query($sqql, $con) or trigger_error("SQL", E_USER_ERROR);

// while there are rows to be fetched...
while ($list = mysql_fetch_assoc($result)) {
   // echo data
   echo "<div class='sky_cont'>
         <div class='sky_vid'><a class='video' href='" .$list['url'] . "'><img src='images/4.PNG' alt='" . $list['title'] ."' border='0' /></a></div><p><h4><a href='" . $list['page_url'] . "' target='_blank'>" . $list['title'] . "</a></h4>" . $list['desc'] . "</p></div>";

} 

/******  build the pagination links ******/
// if not on page 1, don't show back links
if ($currentpage > 1) {
   // show << link to go back to page 1
   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> ";
   // get previous page num
   $prevpage = $currentpage - 1;
   // show < link to go back to 1 page
   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> ";
} 

// range of num links to show
$range = 3;

// loop to show links to range of pages around current page
for ($x = ($currentpage - $range); $x < (($currentpage + $range)  + 1); $x++) {
   // if it's a valid page number...
   if (($x > 0) && ($x <= $totalpages)) {
      // if we're on current page...
      if ($x == $currentpage) {
         // 'highlight' it but don't make a link
         echo " [<b>$x</b>] ";
      // if not current page...
      } else {
         // make it a link
         echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> ";
      }
   } 
}

// if not on last page, show forward and last page links        
if ($currentpage != $totalpages) {
   // get next page
   $nextpage = $currentpage + 1;
    // echo forward link for next page 
   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> ";
   // echo forward link for lastpage
   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> ";
} // end if
/****** end build pagination links ******/


?>


 

Database structure:

id 	- int(11) - Auto increment
url 	- varchar(1000)
page_url 	- varchar(10000)
title 	- varchar(10000)  	
desc  - varchar(10000)  		
date_add 	- varchar(10000)  	
date_rec 	- varchar(10000)  	
place 	- varchar(10000)  	
altitude 	- int(11)
jump_no - int(11)

 

Now, the fields which display in my webpage are the following:

url

desc

 

which means, that the following fields are not displaying at all, for some unknown reason:

title

page_url

 

Can someone please offer an explination as to why some fields from the database are shown, and others are not, even though they are spelled correctly?

 

Thanks,

Matlab

Link to comment
Share on other sites

Also, when i add more entries to the database, only the first one shows up.

 

When using:

$num_rows = mysql_num_rows($result);
echo $num_rows;

 

I get a result of 1, when there are 4 entries in the database.

 

Any ideas how to fix this script?

Link to comment
Share on other sites

I have solved the problem of the script only displaying a few of the variables. I had to create hard links to them and they work.

 

I have come up against another problem. When I am looping through the entries in my database and echoing the data to the webpage, only the first data gets echoed back, and any subsequent echo's are of the first data i.e. if i want to show the first 3 entries of the database, 3 entries are shown, but its the first entry and another 2 repeats of the first entry.

 

Below is my code for the PHP:

<?php

//Connect to the database
$user="USERNAME"; 
$password="PASSWORD";
$database="DATABASE";
$con = mysql_connect("localhost",$user,$password) or die ('Could not connect: ' . mysql_error());



mysql_select_db($database, $con) or die( "Unable to select database");
// find out how many rows are in the table 
$sql = "SELECT * FROM vids";
$result = mysql_query($sql, $con);
$r = mysql_fetch_row($result);
$numrows = $r[0];

// number of rows to show per page
$rowsperpage = 10;

// find out total pages
$totalpages = ceil($numrows / $rowsperpage);

// get the current page or set a default
if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
   // cast var as int
   $currentpage = (int) $_GET['currentpage'];
} else {
   $currentpage = 1;
}

// if current page is greater than total pages...
if ($currentpage > $totalpages) {
   // set current page to last page
   $currentpage = $totalpages;
} // end if
// if current page is less than first page...
if ($currentpage < 1) {
   // set current page to first page
   $currentpage = 1;
} 

// the offset of the list, based on current page 
$offset = ($currentpage - 1) * $rowsperpage;

// get the info from the db 
/*$sqql = "SELECT * FROM vids LIMIT $offset, $rowsperpage";
$result = mysql_query($sqql, $con) or trigger_error("SQL", E_USER_ERROR);*/

// Assign variables for videos
$query  = "SELECT *  FROM vids";
$result = mysql_query($query) or die ('Error: '.mysql_error ());
$row = mysql_fetch_row($result);

$id = $row[0];
$url = $row[1];
$page_url = $row[2];
$title = $row[3];
$desc = $row[4];
$date_add = $row[5];
$date_rec = $row[6];
$place = $row[7];
$altitude = $row[8];
$jump_no = $row[9];

// while there are rows to be fetched...
while ($list = mysql_fetch_assoc($result)) {
   // echo data
    $id = $row[0];
$url = $row[1];
$page_url = $row[2];
$title = $row[3];
$desc = $row[4];
$date_add = $row[5];
$date_rec = $row[6];
$place = $row[7];
$altitude = $row[8];
$jump_no = $row[9];
	 echo "<div class='sky_cont'>
    <div class='sky_vid'><a class='video' href=\"$url\"><img src='images/5.png' alt=\"$title\" Border='0' /></a></div>
<p><h4><a href=\"$page_url\" target='_blank'>$title</a></h4>$desc</p>
    </div>";

}



/******  build the pagination links ******/
// if not on page 1, don't show back links
if ($currentpage > 1) {
   // show << link to go back to page 1
   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> ";
   // get previous page num
   $prevpage = $currentpage - 1;
   // show < link to go back to 1 page
   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> ";
} 

// range of num links to show
$range = 3;

// loop to show links to range of pages around current page
for ($x = ($currentpage - $range); $x < (($currentpage + $range)  + 1); $x++) {
   // if it's a valid page number...
   if (($x > 0) && ($x <= $totalpages)) {
      // if we're on current page...
      if ($x == $currentpage) {
         // 'highlight' it but don't make a link
         echo " [<b>$x</b>] ";
      // if not current page...
      } else {
         // make it a link
         echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> ";
      }
   } 
}

// if not on last page, show forward and last page links        
if ($currentpage != $totalpages) {
   // get next page
   $nextpage = $currentpage + 1;
    // echo forward link for next page 
   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> ";
   // echo forward link for lastpage
   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> ";
} // end if
/****** end build pagination links ******/


?>


Link to comment
Share on other sites

try replacing this...

 

// while there are rows to be fetched...while ($list = mysql_fetch_assoc($result)) {
// echo data    
$id = $row[0];
$url = $row[1];
$page_url = $row[2];
$title = $row[3];
$desc = $row[4];
$date_add = $row[5];
$date_rec = $row[6];
$place = $row[7];
$altitude = $row[8];
$jump_no = $row[9];

 

with this...

// while there are rows to be fetched...
while ($list = mysql_fetch_assoc($result)) {   
// echo data    
$id = $list[0];	
$url = $list[1];	
$page_url = $list[2];	
$title = $list[3];	
$desc = $list[4];	
$date_add = $list[5];	
$date_rec = $list[6];	
$place = $list[7];	
$altitude = $list[8];	
$jump_no = $list[9];

Also - varchar() fields have max 256 characters - if your variable is greater than that it probably will get truncated - so you might consider using TEXT as the field type.

Link to comment
Share on other sites

Ok, I have completed the majority of the work for this website, but there is only one problem I am faced with now.

 

I have displayed all of the videos and short information about them from a database using pagination. My problem is, how do I make it so when the title of one of the videos is clicked, it takes the user to a new page, containing ONLY that video, and ONLY information relating to that video? I assume it will involve some question marks in the URL of the page, but I simply dont know how to do this.

 

Currently, all videos are displayed on several pages, with limited information. The idea (like youtube) is to give a taste of the video from the page, but then a user can click the title to go to a page just for that video to view more details on it.

 

how can i achieve this?

 

Thanks,

MATLAB

Link to comment
Share on other sites

psuedo...

 

<href="showme.php?video_id=<?PHP echo $video_id; >"> Click to view(or put thumb here)</a>

 

showme.php

 

<?PHP

$video_id = $_GET['video_id'];

 

do sql query using $video_id to get pertinent info

 

do what you need to play video and display info

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.