wezze Posted June 5, 2012 Share Posted June 5, 2012 I got a place on my site with pics with numbers beneath the section, what i was wondering is if it is possible when you click number 2 you get the pics of page 2 in place of the existing pics without me needing to make another page in 2 languages everytime. http://mcbevers.be/leden_nl_p1.phpthis is the page clicking on number 2 wont do anything atm any1 got an idea or a link to something i tried google but i dont know how to search this in a couple of words. thx Quote Link to comment https://forums.phpfreaks.com/topic/263720-album-numbers/ Share on other sites More sharing options...
Skewled Posted June 6, 2012 Share Posted June 6, 2012 You can paginate the results to get what you desire.. Example: <?php // Function to build navigational page links function generate_pg_links($cur_page, num_pages) { $page_links1 = ''; // If this page is not the first page, generate the previous link if ($cur_page > 1) { $page_links .='<a href="' . $_SERVER['PHP_SELF'] . '?=' . '&pg=' . ($cur_page - 1) . '"><-</a> '; } else { $page_links .= '<- '; } // Loop through the pages generating the page number links for ($i = 1; $i <= $num_pages; $i++) { if ($cur_page == $i) { $page_links .= ' ' . $i; } else { $page_links .= ' <a href="' . $_SERVER['PHP_SELF'] . '?=' . '&pg=' . $i . '"> ' . $i . '</a>'; } } // If this page is not the last page, generate the next link if ($cur_page < $num_pages) { $page_links .= ' <a href="' . $_SERVER['PHP_SELF'] . '?=' . '&pg=' . ($cur_page + 1) . '">-></a>'; } else { $page_links .= ' ->'; } return $page_links; } // Calculate pagination information $cur_page = isset($_GET['pg']) ? $_GET['pg'] : 1; $results_per_page = 5; // Number of results per page $skip = (($cur_page - 1) * $results_per_page); // Query that gathers the total number of rows returned $numrows = "SELECT * FROM sometable"; $result = mysqli_query($dbc, $numrows); $total = mysqli_num_rows($result); $num_pages = ceil($total / $results_per_page); // Query to limit the results $limitquery = "$pagestuff . " LIMIT $skip, $results_per_page"; $data = mysqli_query($dbc, $query); // Output the data while ($row = mysqli_fetch_array($data)) { // echo img location here } // Generate page links if ($num_pages > 1) { echo '<div id="pg">'; echo '<p>Page: ' . generate_pg_links($cur_page, $num_pages) . '</p>'; echo '</div>'; } ?> I didn't fully test this but if you add your database connection information to the $dbc variable, put the query you need in, and echo out the row for the images like $row['image'] then it should work. But, this is what you seem to need so hope it helps! Quote Link to comment https://forums.phpfreaks.com/topic/263720-album-numbers/#findComment-1351532 Share on other sites More sharing options...
wezze Posted June 6, 2012 Author Share Posted June 6, 2012 i get that i will need to make a sql table but thats it Quote Link to comment https://forums.phpfreaks.com/topic/263720-album-numbers/#findComment-1351674 Share on other sites More sharing options...
Skewled Posted June 7, 2012 Share Posted June 7, 2012 The first portion you have to update with your table that stores the information to the images. // Query that gathers the total number of rows returned $numrows = "SELECT * FROM sometable"; This is where you will format your output for each picture.. wrap it in a div to contain the content while ($row = mysqli_fetch_array($data)) { // echo img location here } Then you can specify the options here: // Calculate pagination information $cur_page = isset($_GET['pg']) ? $_GET['pg'] : 1; $results_per_page = 5; // Number of results per page $skip = (($cur_page - 1) * $results_per_page); Any clearer now? Quote Link to comment https://forums.phpfreaks.com/topic/263720-album-numbers/#findComment-1351793 Share on other sites More sharing options...
wezze Posted June 8, 2012 Author Share Posted June 8, 2012 ok so this is what i got till now1 the php table creation script <?php $con = mysql_connect("localhost","peter","abc123"); if (!$con) { die('Could not connect: ' . mysql_error()); } // Create database if (mysql_query("CREATE DATABASE my_db",$con)) { echo "Database created"; } else { echo "Error creating database: " . mysql_error(); } // Create table mysql_select_db("my_db", $con); $sql = "CREATE TABLE imglink ( id unique auto-increment, linkname varchar(200), linklocation varchar(200) )"; // Execute query mysql_query($sql,$con); mysql_close($con); ?> correct? 2 the script you gave me with the links you pm me <?php // Function to build navigational page links function generate_pg_links($cur_page, num_pages) { $page_links1 = ''; // If this page is not the first page, generate the previous link if ($cur_page > 1) { $page_links .='<a href="' . $_SERVER['PHP_SELF'] . '?=' . '&pg=' . ($cur_page - 1) . '"><-</a> '; } else { $page_links .= '<- '; } // Loop through the pages generating the page number links for ($i = 1; $i <= $num_pages; $i++) { if ($cur_page == $i) { $page_links .= ' ' . $i; } else { $page_links .= ' <a href="' . $_SERVER['PHP_SELF'] . '?=' . '&pg=' . $i . '"> ' . $i . '</a>'; } } // If this page is not the last page, generate the next link if ($cur_page < $num_pages) { $page_links .= ' <a href="' . $_SERVER['PHP_SELF'] . '?=' . '&pg=' . ($cur_page + 1) . '">-></a>'; } else { $page_links .= ' ->'; } return $page_links; } // Calculate pagination information $cur_page = isset($_GET['pg']) ? $_GET['pg'] : 1; $results_per_page = 5; // Number of results per page $skip = (($cur_page - 1) * $results_per_page); // Query that gathers the total number of rows returned $numrows = "SELECT * FROM imglink"; $result = mysqli_query($dbc, $numrows); $total = mysqli_num_rows($result); $num_pages = ceil($total / $results_per_page); // Query to limit the results $limitquery = "$pagestuff . " LIMIT $skip, $results_per_page"; $data = mysqli_query($dbc, $query); // Output the data while ($row = mysqli_fetch_array($data)) { // echo imglocation } // Generate page links if ($num_pages > 1) { echo '<div id="pg">'; echo '<p>Page: ' . generate_pg_links($cur_page, $num_pages) . '</p>'; echo '</div>'; } ?> So if this is correct can i make this an include file? thx Quote Link to comment https://forums.phpfreaks.com/topic/263720-album-numbers/#findComment-1352151 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.