MATLAB Posted August 10, 2010 Share Posted August 10, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/210355-creation-of-image-album-website/ Share on other sites More sharing options...
xcoderx Posted August 10, 2010 Share Posted August 10, 2010 show ur codes and will tell how to set limit Quote Link to comment https://forums.phpfreaks.com/topic/210355-creation-of-image-album-website/#findComment-1097709 Share on other sites More sharing options...
MATLAB Posted August 10, 2010 Author Share Posted August 10, 2010 I have not started coding anything, I was unsure on how to go about it in the first place. I was just looking for some ideas on how to do it, instead of code alterations. Quote Link to comment https://forums.phpfreaks.com/topic/210355-creation-of-image-album-website/#findComment-1097710 Share on other sites More sharing options...
xcoderx Posted August 10, 2010 Share Posted August 10, 2010 google for pagination tutorials then. Quote Link to comment https://forums.phpfreaks.com/topic/210355-creation-of-image-album-website/#findComment-1097713 Share on other sites More sharing options...
MATLAB Posted August 10, 2010 Author Share Posted August 10, 2010 Thanks a lot mate Quote Link to comment https://forums.phpfreaks.com/topic/210355-creation-of-image-album-website/#findComment-1097714 Share on other sites More sharing options...
MATLAB Posted August 11, 2010 Author Share Posted August 11, 2010 How can I make a new page be created on the fly, when a thumbnail of a video is clicked? I know how I could display the details of the video, its just the creation of the page I am struggling to figure out. Quote Link to comment https://forums.phpfreaks.com/topic/210355-creation-of-image-album-website/#findComment-1098027 Share on other sites More sharing options...
litebearer Posted August 11, 2010 Share Posted August 11, 2010 pass the id of the full image as a url variable to the display page (example here http://nstoia.com/easy_family/easy_tree/f_view.php) Quote Link to comment https://forums.phpfreaks.com/topic/210355-creation-of-image-album-website/#findComment-1098035 Share on other sites More sharing options...
MATLAB Posted August 11, 2010 Author Share Posted August 11, 2010 thanks for the answer! il have to look at a tutorial for this, im quite new to php. Quote Link to comment https://forums.phpfreaks.com/topic/210355-creation-of-image-album-website/#findComment-1098037 Share on other sites More sharing options...
litebearer Posted August 11, 2010 Share Posted August 11, 2010 btw, another example but with thumbs and pagination http://nstoia.com/easy_family/easy_album/a_view.php Quote Link to comment https://forums.phpfreaks.com/topic/210355-creation-of-image-album-website/#findComment-1098039 Share on other sites More sharing options...
MATLAB Posted August 19, 2010 Author Share Posted August 19, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/210355-creation-of-image-album-website/#findComment-1101177 Share on other sites More sharing options...
MATLAB Posted August 19, 2010 Author Share Posted August 19, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/210355-creation-of-image-album-website/#findComment-1101180 Share on other sites More sharing options...
MATLAB Posted August 19, 2010 Author Share Posted August 19, 2010 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 ******/ ?> Quote Link to comment https://forums.phpfreaks.com/topic/210355-creation-of-image-album-website/#findComment-1101301 Share on other sites More sharing options...
litebearer Posted August 19, 2010 Share Posted August 19, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/210355-creation-of-image-album-website/#findComment-1101341 Share on other sites More sharing options...
MATLAB Posted August 19, 2010 Author Share Posted August 19, 2010 changing the code you said didnt do anything unfortunately, infact it removed the description and title from the records echo'd. Thanks anyway Quote Link to comment https://forums.phpfreaks.com/topic/210355-creation-of-image-album-website/#findComment-1101354 Share on other sites More sharing options...
litebearer Posted August 19, 2010 Share Posted August 19, 2010 sorry - was moving too fast... mysql_fetch_assoc requires using the field NAMES not numeric value. to use either name or numeric value, use mysql_fetch_array Quote Link to comment https://forums.phpfreaks.com/topic/210355-creation-of-image-album-website/#findComment-1101382 Share on other sites More sharing options...
MATLAB Posted August 26, 2010 Author Share Posted August 26, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/210355-creation-of-image-album-website/#findComment-1104047 Share on other sites More sharing options...
MATLAB Posted August 27, 2010 Author Share Posted August 27, 2010 any ideas people? Thanks, Matlab Quote Link to comment https://forums.phpfreaks.com/topic/210355-creation-of-image-album-website/#findComment-1104396 Share on other sites More sharing options...
litebearer Posted August 27, 2010 Share Posted August 27, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/210355-creation-of-image-album-website/#findComment-1104447 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.