AdRock Posted August 22, 2008 Share Posted August 22, 2008 I have 2 different scripts and i would like to combine them into one so that they work together What i want to do is query the database, get all the records (which are paths to images) and display them in a table which is 4 columns wide. When a set number of images are output into the table, create a link to a new page (using pagination) e.g. Say i wanted 40 images per page 4 columns, 10 rows and I have 120 images in database, i get 3 pages. I have a script to output all the images into a table and i have a seperate script for the pagination. How do i combine them into 1? The script that output all images to a table $cat = $_GET['cat']; define ("NUMCOLS",4); //include_once("includes/connection.php"); $res = mysql_query("SELECT id,thumb,cat FROM image WHERE cat='jack'"); $count = 0; $counter= 1; echo "<table border='0' id='gallery'>"; while (list($id,$thumb,$cat) = mysql_fetch_row($res)) { if ($count % NUMCOLS == 0) echo "<tr>\n"; # new row echo "<td><div class='img-shadow'><a href='/gallery/$cat/image/$counter'><img src='/images/gallery/thumbs/$thumb' alt='Jack' style='border:none' /></a></div></td>\n"; $count++; $counter++; if ($count % NUMCOLS == 0) echo "</tr>\n"; # end row } # end row if not already ended if ($count % NUMCOLS != 0) { while ($count++ % NUMCOLS) echo "<td> </td>"; echo "</tr>\n"; } echo "</table>"; and the script for the paging $webpage = basename(image); function pagination_five($total_pages,$page){ global $webpage; global $cat; $max_links = 7; $h=1; if($page>$max_links){ $h=(($h+$page)-$max_links); } if($page>=1){ $max_links = $max_links+($page-1); } if($max_links>$total_pages){ $max_links=$total_pages+1; } echo '<div class="page_numbers"> <ul>'; if($page>"1"){ echo "<li class='current'><a href='/gallery/".$cat."/".$webpage."/1'>First</a></li> <li class='current'><a href='/gallery/".$cat."/".$webpage."/".($page-1)."'>Prev</a></li> "; } if($total_pages!=1){ for ($i=$h;$i<$max_links;$i++){ if($i==$page){ echo '<li><a class="current">'.$i.'</a></li>'; } else{ echo '<li><a href="/gallery/'.$cat.'/'.$webpage.'/'.$i.'">'.$i.'</a> </li>'; } } } if(($page >="1")&&($page!=$total_pages)){ echo '<li class="current"><a href="/gallery/'.$cat.'/'.$webpage.'/'.($page+1).'">Next</a></li> <li class="current"><a href="/gallery/'.$cat.'/'.$webpage.'/'.$total_pages.'">Last</a></li> '; } echo '</ul> </div> '; } $result = mysql_query("Select count(*) from image WHERE cat='$cat'") or die (mysql_error()); $numrows = mysql_fetch_row($result); $url = $result['cat']; if(isset($_GET['pagenum'])?$page = $_GET['pagenum']:$page = 1); $entries_per_page = 1; $total_pages = ceil($numrows[0]/$entries_per_page); $offset = (($page * $entries_per_page) - $entries_per_page); $result = mysql_query("SELECT id,image,thumb, cat FROM image WHERE cat='$cat' ORDER BY id ASC LIMIT $offset,$entries_per_page"); pagination_five($total_pages,$page); Link to comment https://forums.phpfreaks.com/topic/120926-combing-2-script-into-1/ Share on other sites More sharing options...
AjBaz100 Posted August 23, 2008 Share Posted August 23, 2008 cut and paste the pagination into the first script??? Link to comment https://forums.phpfreaks.com/topic/120926-combing-2-script-into-1/#findComment-623519 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.