Page 1 of 1

Image Gallery

Posted: Sat May 08, 2010 5:27 am
by tito85
Hi,

I am trying to do an image gallery for a movie database. I did the following code, however movies found in the database are being listed one under each other. I would like that the movies be displayed 5 movies in a row under each other.

Any help please?

Code: Select all

<?php
  //this is used to connect with the database
  require('dbconnect.php');
  include('securitycheck.php');
  session_start();
?>
<!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>Online Movie Database - Coming Soon</title>
<link rel="stylesheet" href="CSSWebStyles/style.css" />
<link rel="shortcut icon" href="Images/filmicon.ico"/>
</head>
<body>
<div id="website">
<?php
  //will include the code from banner.php file (banner & navigation)
  include('banner.php');
?>
<?php
  //checking if the user is an administrator
  if (isset($_SESSION['superadmin'])) {
      if ($_SESSION['superadmin'])
          include('adminmenu.php');
  }
?>
<div id="content">
<div id="contentgeneral">
<br />
<center>
<h2>Coming Soon Movies</h2><p />
</center>
<br />
<?php
  $select = "SELECT * FROM movies WHERE MovieReleaseDate >= '" . date("Y-m-d") . "' ORDER BY MovieReleaseDate ASC";
  $result = mysql_query($select);
  if (mysql_num_rows($result) > 0) {
      while ($movie = mysql_fetch_array($result)) {
		  echo "<div style=\"overflow: auto;\">";
          echo "<hr style=\"border: 1px solid #06C\" />";
          echo "<table><tr>";
		  echo "<td>";
          echo '<center><img src="images/movies/' . $movie['Filename'] . '" width="125" height="185" /></center>';
		  echo "</td>";
          echo "</tr><tr>";
		  echo "<td>";
		  echo "<center><a href=\"moviedetails.php?id=" . $movie['MovieID'] . "\">" . $movie['Title'] . "</a></center>";
		  echo "</td>";
          echo "</tr><tr>";
		  echo "<td>";
		  echo "<center>will be released on " . date("d/m/Y", strtotime($movie['MovieReleaseDate'])) . " </center>";
		  echo "</td>";
          echo "</tr></table>";
          echo "<hr style=\"border: 1px solid #06C\" />";
          echo "</div>";  
      }
  } else {
      echo "<center><b>No Coming Soon Movies found</b></center>";
  }
?>
</div>
</div>
<?php
  //will include the code from footer.php file
  include('footer.php');
?>
</div>
</body>
</html>

Re: Image Gallery

Posted: Sat May 08, 2010 2:16 pm
by jraede
That's not really a PHP or SQL issue. Two solutions jump out: 1, you can use the LIMIT syntax to display 5 entries at a time and run as many queries as necessary to get all the information. Or 2, which is much easier, just wrap each entry in a div or make it an unordered list, and have the divs float left or display:inline-block. You can mess with the widths & margins so you get 5 per row.

Re: Image Gallery

Posted: Sat May 08, 2010 2:48 pm
by tito85
Thanks for your help however I would like some example as it seems a bit difficult for me...

Re: Image Gallery

Posted: Sat May 08, 2010 2:55 pm
by John Cartwright
You can probably get away with changing

Code: Select all

echo "<div style=\"overflow: auto;\">";
to

Code: Select all

echo "<div style=\"float: left; width: 19%\">";
Which will put 5 div's side by side, and when overflowed, the next div will go below the previous.

Re: Image Gallery

Posted: Sun May 09, 2010 4:12 am
by tito85
Thanks it is working fine!!!