e4art
asked on
Help Building Page links in Gallery
I have a photo gallery working with a statement under it saying "showing page 1 of 2" if you're on page 1. Under that says it has the "next" button which brings you to the next page. If you're on page 2, the previous button appears. All working fine. Now say I have 30 pages. Can you help me add a small drop down menu that will allow the user to go to any page they want? When you click on the drop down menu you will see the option t click on what ever page you want "1" through "30." Seems simple enough. I know how to biukd a drop down menu, but where do I put it in my gallery it knows what page to call on?
Here's some of my gallery script where this drop down menu might go. Can you tell me where and what syntax to use? THANKS!!
// Figure out the total number of results in DB:
$total_results = mysql_result(mysql_query(" SELECT COUNT(*) as Num FROM gallery_photos WHERE photo_category=".addslashe s($cid)."" ),0);
// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);
if ($total_pages >1)
{ // build links if more than one page
// Build Page Number Hyperlinks
$result_final .= "<tr><td colspan='".$number_of_thum bs_in_row. "'>Showing Page: ".$page.' of '.$total_pages."<br>";
// Build Previous Link
if($page > 1){
$prev = ($page - 1);
$result_final .= "\n<a href=\"".$_SERVER['PHP_SEL F']."?cid= $cid&page= $prev\" title='Previous Page'><< Prev</a>";
}
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
$result_final .= " [$i]";
} else {
$result_final .= "\n<a href=\"".$_SERVER['PHP_SEL F']."?cid= $cid&page= $i\" title='Page ".$i."'>$i</a>";
}
}
// Build Next Link
if($page < $total_pages){
$next = ($page + 1);
$result_final .= "\n<a href=\"".$_SERVER['PHP_SEL F']."?cid= $cid&page= $next\" title='Next Page'>Next >></a>";
}
$result_final .= "\n</td></tr>";
}
else
{
$result_final .= "\n";
}
}
}
}
Here's some of my gallery script where this drop down menu might go. Can you tell me where and what syntax to use? THANKS!!
// Figure out the total number of results in DB:
$total_results = mysql_result(mysql_query("
// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);
if ($total_pages >1)
{ // build links if more than one page
// Build Page Number Hyperlinks
$result_final .= "<tr><td colspan='".$number_of_thum
// Build Previous Link
if($page > 1){
$prev = ($page - 1);
$result_final .= "\n<a href=\"".$_SERVER['PHP_SEL
}
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
$result_final .= " [$i]";
} else {
$result_final .= "\n<a href=\"".$_SERVER['PHP_SEL
}
}
// Build Next Link
if($page < $total_pages){
$next = ($page + 1);
$result_final .= "\n<a href=\"".$_SERVER['PHP_SEL
}
$result_final .= "\n</td></tr>";
}
else
{
$result_final .= "\n";
}
}
}
}
i did not test below code. it is just a clue how u can get the result.
<?php
//intTotalPages = objRS.PageCount
echo '<table border="0" align="center">';
echo '<tr><td width=250 align=center>Found : $no_of_records<b>';
echo '</b> Record(s)</td>';
echo '<td width=250 align=center>';
?>
Page:
<select onChange="if(options[selec tedIndex]. value) window.location.href=
(options[selectedIndex].va lue)">
<?php
for($i = 1; $i = $total_pages; ;){
echo '<option value="$_SERVER['PHP_SELF' ].?cid=$ci d&page=$i- 1">$i</opt ion>';
}
$i = 0
echo '</select> of $total_pages';
<?php
//intTotalPages = objRS.PageCount
echo '<table border="0" align="center">';
echo '<tr><td width=250 align=center>Found : $no_of_records<b>';
echo '</b> Record(s)</td>';
echo '<td width=250 align=center>';
?>
Page:
<select onChange="if(options[selec
(options[selectedIndex].va
<?php
for($i = 1; $i = $total_pages; ;){
echo '<option value="$_SERVER['PHP_SELF'
}
$i = 0
echo '</select> of $total_pages';
ASKER
Good information, but I'm new to PHP and I'm still not sure where to place this code. I've been trying it out, with NO luck. I get the drop down menu to appear, but with only page 1 coming up. I have so far at least two pages. Why isn't the second page coming up? I'm already quering my database, so I'm not sure if the following script is correct. I downloaded the zip file from the tutorial you sent me to, but not sure if I replaced the variables correctly. Can you let me know?
echo "<select name='cat' onchange=\"reload(this.for m)\"><opti on value=''>1</option>";
while($page = mysql_fetch_array($total_p ages)) {
if($page['category_id']==@ $cat){echo "<option selected value='$page[category_id]' >$page[cat egory]</op tion>"."<B R>";}
else{echo "<option value='$page[category_id]' >$page[cat egory]</op tion>";}
}
echo "</select>";
-------------------
I put the following code in my head tag, IS THIS CORRECT?
-------------------
<SCRIPT language=JavaScript>
function reload(form)
{
var val=form.cat.options[form. cat.option s.selected Index].val ue;
self.location='album.php?c at=' + val ;
}
</script>
Just need to create one drop down list based on my results. I already get the resluts where it says "Showing Page: 1 of 2", so it knows how many pages there are, but how do I make that list so the user doesn't have to keep click the "next" button. This way they can go to what ever page they want.
HELP PLEASE! THANKS. WHERE IN MY CODE ABOVE SHOULD I ADD THE CODE?
echo "<select name='cat' onchange=\"reload(this.for
while($page = mysql_fetch_array($total_p
if($page['category_id']==@
else{echo "<option value='$page[category_id]'
}
echo "</select>";
-------------------
I put the following code in my head tag, IS THIS CORRECT?
-------------------
<SCRIPT language=JavaScript>
function reload(form)
{
var val=form.cat.options[form.
self.location='album.php?c
}
</script>
Just need to create one drop down list based on my results. I already get the resluts where it says "Showing Page: 1 of 2", so it knows how many pages there are, but how do I make that list so the user doesn't have to keep click the "next" button. This way they can go to what ever page they want.
HELP PLEASE! THANKS. WHERE IN MY CODE ABOVE SHOULD I ADD THE CODE?
Based on the way your hyperlinks are made, I don't think your code above is correct:
Right after
"if ($total_pages >1)" in your code add
add:
$theSelect = "<select name='cat' onchange=\"reload(this)\"> "
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
$theSelect .= "<option checked value=/"".$_SERVER['PHP_SE LF']."?cid =".$cid."& page=".$i- 1."/">". $i . "</option>";
} else {
$theSelect .= "<option value=/"".$_SERVER['PHP_SE LF']."?cid =".$cid."& page=".$i- 1."/">". $i . "</option>";
}
}
$theSelect .= "</select>";
Now $theSelect has your drop down box.
Where ever that needs to go on your page... simply put
<?=$theSelect?>
<script type="text\javascript">
function reload(oSel) {
var val=oSel[oSel.selectedInde x].value;
self.location=val ;
}
</script>
Right after
"if ($total_pages >1)" in your code add
add:
$theSelect = "<select name='cat' onchange=\"reload(this)\">
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
$theSelect .= "<option checked value=/"".$_SERVER['PHP_SE
} else {
$theSelect .= "<option value=/"".$_SERVER['PHP_SE
}
}
$theSelect .= "</select>";
Now $theSelect has your drop down box.
Where ever that needs to go on your page... simply put
<?=$theSelect?>
<script type="text\javascript">
function reload(oSel) {
var val=oSel[oSel.selectedInde
self.location=val ;
}
</script>
ASKER
I tried using your script above and ran into errors. I added the following code just as you said right after: "if ($total_pages >1)" , I added:
$theSelect = "<select name='cat' onchange=\"reload(this)\"> "
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
$theSelect .= "<option checked value=/"".$_SERVER['PHP_SE LF']."?cid =".$cid."& page=".$i- 1."/">". $i . "</option>";
} else {
$theSelect .= "<option value=/"".$_SERVER['PHP_SE LF']."?cid =".$cid."& page=".$i- 1."/">". $i . "</option>";
}
}
$theSelect .= "</select>";
<?=$theSelect?>
ALSO seems you wanted me to replace the javascript I had in the head tag with the following?
<script type="text\javascript">
function reload(oSel) {
var val=oSel[oSel.selectedInde x].value;
self.location=val ;
}
</script>
This goes in the head tag, correct?
Then I placed the following code <?php =$theSelect?> where I wanted the drop down menu to show up. When I ran the script in my browser I get an error message:
"Parse error: parse error, unexpected T_FOR in "this is where my url is" on line 212"
What am I doing wrong??
$theSelect = "<select name='cat' onchange=\"reload(this)\">
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
$theSelect .= "<option checked value=/"".$_SERVER['PHP_SE
} else {
$theSelect .= "<option value=/"".$_SERVER['PHP_SE
}
}
$theSelect .= "</select>";
<?=$theSelect?>
ALSO seems you wanted me to replace the javascript I had in the head tag with the following?
<script type="text\javascript">
function reload(oSel) {
var val=oSel[oSel.selectedInde
self.location=val ;
}
</script>
This goes in the head tag, correct?
Then I placed the following code <?php =$theSelect?> where I wanted the drop down menu to show up. When I ran the script in my browser I get an error message:
"Parse error: parse error, unexpected T_FOR in "this is where my url is" on line 212"
What am I doing wrong??
add my code just above ur code where :
// Build Next Link
if($page < $total_pages){
$next = ($page + 1);
$result_final .= "\n<a href=\"".$_SERVER['PHP_SEL F']."?cid= $cid&page= $next\" title='Next Page'>Next >></a>";
}
//////////////so after adding code look like :
// no need to write javascript for reloading page. javascript code is already included below
echo '<table border="0" align="center">';
echo '<tr><td width=250 align=center>Found : $no_of_records<b>';
echo '</b> Record(s)</td>';
echo '<td width=250 align=center>';
?>
Page:
<select onChange="if(options[selec tedIndex]. value) window.location.href=
(options[selectedIndex].va lue)">
<?php
for($i = 1; $i = $total_pages; ;){
echo '<option value="$_SERVER['PHP_SELF' ].?cid=$ci d&page=$i- 1">$i</opt ion>';
}
$i = 0
echo '</select> of $total_pages';
// Build Next Link
if($page < $total_pages){
$next = ($page + 1);
$result_final .= "\n<a href=\"".$_SERVER['PHP_SEL F']."?cid= $cid&page= $next\" title='Next Page'>Next >></a>";
}
// Build Next Link
if($page < $total_pages){
$next = ($page + 1);
$result_final .= "\n<a href=\"".$_SERVER['PHP_SEL
}
//////////////so after adding code look like :
// no need to write javascript for reloading page. javascript code is already included below
echo '<table border="0" align="center">';
echo '<tr><td width=250 align=center>Found : $no_of_records<b>';
echo '</b> Record(s)</td>';
echo '<td width=250 align=center>';
?>
Page:
<select onChange="if(options[selec
(options[selectedIndex].va
<?php
for($i = 1; $i = $total_pages; ;){
echo '<option value="$_SERVER['PHP_SELF'
}
$i = 0
echo '</select> of $total_pages';
// Build Next Link
if($page < $total_pages){
$next = ($page + 1);
$result_final .= "\n<a href=\"".$_SERVER['PHP_SEL
}
ASKER
Nope, still getting errors. Is there something missing like a bracket or semicolon or something? I was looking at both your codes (gawai and rdivilbiss) It's hard to know what to use. But here's what I have... and by the way...in your script gawai, below, there are two semicolons. Is this correct?
for($i = 1; $i = $total_pages; ;){
Here's my error which comes up in the browser:
Parse error: parse error, unexpected ';', expecting ')' in //this is my ur//l on line 230
Line 230 says:
echo '<option value="$_SERVER['PHP_SELF' ].?cid=$ci d&page=$i- 1">$i</opt ion>';
Here's my big chunk of code for this section. Do you see any errors?
// Figure out the total number of results in DB:
$total_results = mysql_result(mysql_query(" SELECT COUNT(*) as Num FROM gallery_photos WHERE photo_category=".addslashe s($cid)."" ),0);
// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);
if ($total_pages >1)
{ // build links if more than one page
// Build Page Number Hyperlinks
$result_final .= "<tr><td colspan='".$number_of_thum bs_in_row. "'>Showing Page: ".$page.' of '.$total_pages."<br>";
// Build Previous Link
if($page > 1){
$prev = ($page - 1);
$result_final .= "\n<a href=\"".$_SERVER['PHP_SEL F']."?cid= $cid&page= $prev\" title='Previous Page'><< Prev</a>";
}
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
$result_final .= " [$i]";
} else {
$result_final .= "\n<a href=\"".$_SERVER['PHP_SEL F']."?cid= $cid&page= $i\" title='Page ".$i."'>$i</a>";
}
}
echo '<table border="0" align="center">';
echo '<tr><td width=250 align=center>Found : $no_of_records<b>';
echo '</b> Record(s)</td>';
echo '<td width=250 align=center>';
?>
Page:
<select onChange="if(options[selec tedIndex]. value) window.location.href=
(options[selectedIndex].va lue)">
<?php
for($i = 1; $i = $total_pages; ;){
echo '<option value="$_SERVER['PHP_SELF' ].?cid=$ci d&page=$i- 1">$i</opt ion>';
}
$i = 0
echo '</select> of $total_pages';
// Build Next Link
if($page < $total_pages){
$next = ($page + 1);
$result_final .= "\n<a href=\"".$_SERVER['PHP_SEL F']."?cid= $cid&page= $next\" title='Next Page'>Next >></a>";
}
$result_final .= "\n</td></tr>";
}
else
{
$result_final .= "\n";
}
}
}
}
for($i = 1; $i = $total_pages; ;){
Here's my error which comes up in the browser:
Parse error: parse error, unexpected ';', expecting ')' in //this is my ur//l on line 230
Line 230 says:
echo '<option value="$_SERVER['PHP_SELF'
Here's my big chunk of code for this section. Do you see any errors?
// Figure out the total number of results in DB:
$total_results = mysql_result(mysql_query("
// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);
if ($total_pages >1)
{ // build links if more than one page
// Build Page Number Hyperlinks
$result_final .= "<tr><td colspan='".$number_of_thum
// Build Previous Link
if($page > 1){
$prev = ($page - 1);
$result_final .= "\n<a href=\"".$_SERVER['PHP_SEL
}
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
$result_final .= " [$i]";
} else {
$result_final .= "\n<a href=\"".$_SERVER['PHP_SEL
}
}
echo '<table border="0" align="center">';
echo '<tr><td width=250 align=center>Found : $no_of_records<b>';
echo '</b> Record(s)</td>';
echo '<td width=250 align=center>';
?>
Page:
<select onChange="if(options[selec
(options[selectedIndex].va
<?php
for($i = 1; $i = $total_pages; ;){
echo '<option value="$_SERVER['PHP_SELF'
}
$i = 0
echo '</select> of $total_pages';
// Build Next Link
if($page < $total_pages){
$next = ($page + 1);
$result_final .= "\n<a href=\"".$_SERVER['PHP_SEL
}
$result_final .= "\n</td></tr>";
}
else
{
$result_final .= "\n";
}
}
}
}
Working code, live example.
http://www.rodsdot.com/ee/Q_22470018.php
If you get errors like missing or expected ;, just look to see what is wrong with the code.
http://www.rodsdot.com/ee/Q_22470018.php
If you get errors like missing or expected ;, just look to see what is wrong with the code.
<?PHP
// Figure out the total number of results in DB:
$total_results = 197;
$max_results = 20;
$number_of_thumbs_in_row = 6;
$cid = 5;
$result_final = "";
$select_list = "<select size=\"1\" onchange=\"document.location=this[this.selectedIndex].value\">";
$page = 1;
if (isset($_GET["page"])) {
$page=$_GET["page"];
}
// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);
if ($total_pages >1) { // build links if more than one page
// Build Page Number Hyperlinks
$result_final .= "<tr><td colspan='".$number_of_thumbs_in_row."'>";
$pageOfPages = "Page: ".$page.' of '.$total_pages;
// Build Previous Link
if($page > 1){
$prev = ($page - 1);
$prevLink = "<a href=\"".$_SERVER['PHP_SELF']."?cid=$cid&page=$prev\" title=\"Previous Page\"><< Prev</a>";
} else {
$prevLink = "<< Prev";
}
$pageNoLinks = "";
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
$pageNoLinks .= " [$i]";
$select_list .= "<option selected value=\"" . $_SERVER['PHP_SELF'] ."?cid=". $cid ."&page=". $i ."\">Page ". $i ."</option>";
} else {
if (($total_pages > 5)&&($i>2)) {
if ($i==3) {
$pageNoLinks .= "...";
}
} else {
$pageNoLinks .= "\n<a href=\"".$_SERVER['PHP_SELF']."?cid=$cid&page=$i\" title='Page ".$i."'>$i</a>";
}
$select_list .= "<option value=\"" . $_SERVER['PHP_SELF'] ."?cid=". $cid ."&page=". $i ."\">Page ". $i ."</option>";
}
}
// Build Next Link
if($page < $total_pages){
$next = ($page + 1);
$nextLink = "<a href=\"".$_SERVER['PHP_SELF']."?cid=$cid&page=$next\" title=\"Next Page\">Next >></a>";
}
$select_list .= "</select>";
$result_final .= $pageOfPages ." (" . $total_results ." images)" . " Go to page " . $select_list;
$result_final .= " " . $prevLink ." / ". $nextLink;
$result_final .= "</td></tr>";
}else{
$result_final .= "\n";
}
?>
<html>
<head>
<title>Select Navigation</title>
<style type="text/css">
<!--
.code { color: #000000; border: 1px dashed #000000; padding: 5px; background-color:
#FFFFCC }
-->
</style>
</head>
<body>
<p><? echo $result_final; ?></p>
<div class="code"><pre>
<?PHP
// Figure out the total number of results in DB:
$total_results = 197;
$max_results = 20;
$number_of_thumbs_in_row = 6;
$cid = 5;
$result_final = "";
$select_list = "<select size=\"1\" onchange=\"document.location=this[this.selectedIndex].value\">";
$page = 1;
if (isset($_GET["page"])) {
$page=$_GET["page"];
}
// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);
if ($total_pages >1) { // build links if more than one page
// Build Page Number Hyperlinks
$result_final .= "<tr><td colspan='".$number_of_thumbs_in_row."'>";
$pageOfPages = "Page: ".$page.' of '.$total_pages;
// Build Previous Link
if($page > 1){
$prev = ($page - 1);
$prevLink = "<a href=\"".$_SERVER['PHP_SELF']."?cid=$cid&page=$prev\" title=\"Previous Page\">&lt;&lt; Prev</a>";
} else {
$prevLink = "&lt;&lt; Prev";
}
$pageNoLinks = "";
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
$pageNoLinks .= "&nbsp;[$i]";
$select_list .= "<option selected value=\"" . $_SERVER['PHP_SELF'] ."?cid=". $cid ."&page=". $i ."\">Page ". $i ."</option>";
} else {
if (($total_pages > 5)&&($i>2)) {
if ($i==3) {
$pageNoLinks .= "...";
}
} else {
$pageNoLinks .= "\n<a href=\"".$_SERVER['PHP_SELF']."?cid=$cid&page=$i\" title='Page ".$i."'>$i</a>";
}
$select_list .= "<option value=\"" . $_SERVER['PHP_SELF'] ."?cid=". $cid ."&page=". $i ."\">Page ". $i ."</option>";
}
}
// Build Next Link
if($page < $total_pages){
$next = ($page + 1);
$nextLink = "<a href=\"".$_SERVER['PHP_SELF']."?cid=$cid&page=$next\" title=\"Next Page\">Next &gt;&gt;</a>";
}
$select_list .= "</select>";
$result_final .= $pageOfPages ." (" . $total_results ." images)" . "&nbsp;&nbsp;Go to page&nbsp;" . $select_list;
$result_final .= "&nbsp;&nbsp;" . $prevLink ." / ". $nextLink;
$result_final .= "</td></tr>";
}else{
$result_final .= "\n";
}
?>
<html>
<head>
<title>Select Navigation</title>
</head>
<body>
<p><? echo $result_final; ?></p>
</body>
</html>
</pre></div>
</body>
</html>
ASKER
Working great! Thanks so much, but I was wondering if you can help me tweak the results a bit. I worked with your code so now when I preview it in the browser it says:
page 1 of 2
[1] 2 next >> go to page [2] This is the drop down menu.
Now what if I don't want the page numbers showing. Say I end up of having 30 pages for this category. I don't want to show [1] 2 3 4 5 6 7 8 9 10 11 12, etc.
I just want to say for example:
page 1 of 2 (24 images) --> go to page [2] >> previous / next
Also this will all be in one row like I have it above. Where the previous and next buttons appear AFTER the drop down page menu. Was having trouble looking through the code to see how to eliminate this section with all the pages showing at once. We can just commment it out for now so I can always go back to it if I change my mind later on. Can you show me how to do that please? You can also see that I want to display the number of images in the category. I have this working fine in my gallery when the category listings appear. It shows how many photos are in that category. Don't see why we can't just call upon this result again and place it with the page number results. Just not sure how to add this code to this section though.
Here's my category code below. And then below that I cut to the section with what I used from you.
<?php
// initialization
$result_array = array();
$counter = 0;
$cid = (int)($_GET['cid']);
$pid = (int)($_GET['pid']);
// Category Listing
if( empty($cid) && empty($pid) )
{
$number_of_categories_in_r ow = 4;
$result = mysql_query( "SELECT c.category_id,c.category_n ame,COUNT( photo_id)
FROM gallery_category as c
LEFT JOIN gallery_photos as p ON p.photo_category = c.category_id
GROUP BY c.category_id" );
while( $row = mysql_fetch_array( $result ) )
{
$result_array[] = "<a href='album.php?cid=".$row [0]."'>".$ row[1]."</ a> "."(".$row[2].")";
}
mysql_free_result( $result );
$result_final = "<tr>\n";
foreach($result_array as $category_link)
{
if($counter == $number_of_categories_in_r ow)
{
$counter = 1;
$result_final .= "\n</tr>\n<tr>\n";
}
else
$counter++;
$result_final .= "\t<td>".$category_link."< /td>\n";
}
if($counter)
{
if($number_of_categories_i n_row-$cou nter)
$result_final .= "</tr>";
}
}
//Then we come to my thumbnail code.
//And here is the code where we added the drop down menu for the page links. This is where I want to add the image count like I mentioned above, and get rid of all those page numbers showing.
// Figure out the total number of results in DB:
$total_results = mysql_result(mysql_query(" SELECT COUNT(*) as Num FROM gallery_photos WHERE photo_category=".addslashe s($cid)."" ),0);
$select_list = "<select size=\"1\" onchange=\"document.locati on=this[th is.selecte dIndex].va lue\">";
// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);
if ($total_pages >1)
{ // build links if more than one page
// Build Page Number Hyperlinks
$result_final .= "<tr><td colspan='".$number_of_thum bs_in_row. "'>page ".$page.' of '.$total_pages."<br>";
// Build Previous Link
if($page > 1){
$prev = ($page - 1);
$result_final .= "\n<a href=\"".$_SERVER['PHP_SEL F']."?cid= $cid&page= $prev\" title='Previous Page'><< previous</a>";
}
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
$result_final .= " [$i]";
$select_list .= "<option selected value=\"" . $_SERVER['PHP_SELF'] ."?cid=". $cid ."&page=". $i ."\"> ". $i ."</option>";
} else {
$result_final .= "\n<a href=\"".$_SERVER['PHP_SEL F']."?cid= $cid&page= $i\" title='Page ".$i."'>$i</a>";
$select_list .= "<option value=\"" . $_SERVER['PHP_SELF'] ."?cid=". $cid ."&page=". $i ."\"> ". $i ."</option>";
}
}
// Build Next Link
if($page < $total_pages){
$next = ($page + 1);
$result_final .= "\n<a href=\"".$_SERVER['PHP_SEL F']."?cid= $cid&page= $next\" title='Next Page'>next >></a>";
}
//This is where we have our page links displayed.
$result_final .= " go to page "."$select_list
</td></tr>";
$select_list .= "</select>" ;
}else{
$result_final .= "\n";
}
}
}
}
page 1 of 2
[1] 2 next >> go to page [2] This is the drop down menu.
Now what if I don't want the page numbers showing. Say I end up of having 30 pages for this category. I don't want to show [1] 2 3 4 5 6 7 8 9 10 11 12, etc.
I just want to say for example:
page 1 of 2 (24 images) --> go to page [2] >> previous / next
Also this will all be in one row like I have it above. Where the previous and next buttons appear AFTER the drop down page menu. Was having trouble looking through the code to see how to eliminate this section with all the pages showing at once. We can just commment it out for now so I can always go back to it if I change my mind later on. Can you show me how to do that please? You can also see that I want to display the number of images in the category. I have this working fine in my gallery when the category listings appear. It shows how many photos are in that category. Don't see why we can't just call upon this result again and place it with the page number results. Just not sure how to add this code to this section though.
Here's my category code below. And then below that I cut to the section with what I used from you.
<?php
// initialization
$result_array = array();
$counter = 0;
$cid = (int)($_GET['cid']);
$pid = (int)($_GET['pid']);
// Category Listing
if( empty($cid) && empty($pid) )
{
$number_of_categories_in_r
$result = mysql_query( "SELECT c.category_id,c.category_n
FROM gallery_category as c
LEFT JOIN gallery_photos as p ON p.photo_category = c.category_id
GROUP BY c.category_id" );
while( $row = mysql_fetch_array( $result ) )
{
$result_array[] = "<a href='album.php?cid=".$row
}
mysql_free_result( $result );
$result_final = "<tr>\n";
foreach($result_array as $category_link)
{
if($counter == $number_of_categories_in_r
{
$counter = 1;
$result_final .= "\n</tr>\n<tr>\n";
}
else
$counter++;
$result_final .= "\t<td>".$category_link."<
}
if($counter)
{
if($number_of_categories_i
$result_final .= "</tr>";
}
}
//Then we come to my thumbnail code.
//And here is the code where we added the drop down menu for the page links. This is where I want to add the image count like I mentioned above, and get rid of all those page numbers showing.
// Figure out the total number of results in DB:
$total_results = mysql_result(mysql_query("
$select_list = "<select size=\"1\" onchange=\"document.locati
// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);
if ($total_pages >1)
{ // build links if more than one page
// Build Page Number Hyperlinks
$result_final .= "<tr><td colspan='".$number_of_thum
// Build Previous Link
if($page > 1){
$prev = ($page - 1);
$result_final .= "\n<a href=\"".$_SERVER['PHP_SEL
}
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
$result_final .= " [$i]";
$select_list .= "<option selected value=\"" . $_SERVER['PHP_SELF'] ."?cid=". $cid ."&page=". $i ."\"> ". $i ."</option>";
} else {
$result_final .= "\n<a href=\"".$_SERVER['PHP_SEL
$select_list .= "<option value=\"" . $_SERVER['PHP_SELF'] ."?cid=". $cid ."&page=". $i ."\"> ". $i ."</option>";
}
}
// Build Next Link
if($page < $total_pages){
$next = ($page + 1);
$result_final .= "\n<a href=\"".$_SERVER['PHP_SEL
}
//This is where we have our page links displayed.
$result_final .= " go to page "."$select_list
</td></tr>";
$select_list .= "</select>" ;
}else{
$result_final .= "\n";
}
}
}
}
ASKER
Again, just repeating myself, the same line could eventually read:
page 1 of 63 (1000 images) --> go to page [2] >> previous / next
This is just the count of images per category, which I already have implemented. Not the count per page. Just didn't want to confuse you. Hope to hear from you soon. Thanks in advance!
page 1 of 63 (1000 images) --> go to page [2] >> previous / next
This is just the count of images per category, which I already have implemented. Not the count per page. Just didn't want to confuse you. Hope to hear from you soon. Thanks in advance!
ASKER
OK, I figured out which ares to comment out to get rid of the page numbers. Just need help with the other part above. Putting all of this in one row, and listing the images count like in the follwoing order:
page 1 of 63 (1000 images) --> go to page [2] >> previous / next
These are the lines I commented out. See what I noted below.
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
//commented out the line below so we don't get the row of page numbers.
// $result_final .= " [$i]";
$select_list .= "<option selected value=\"" . $_SERVER['PHP_SELF'] ."?cid=". $cid ."&page=". $i ."\"> ". $i ."</option>";
} else {
//Again, I commented out the line below so we don't get the row of page numbers.
// $result_final .= "\n<a href=\"".$_SERVER['PHP_SEL F']."?cid= $cid&page= $i\" title='Page ".$i."'>$i</a>";
$select_list .= "<option value=\"" . $_SERVER['PHP_SELF'] ."?cid=". $cid ."&page=". $i ."\"> ". $i ." </option>";
page 1 of 63 (1000 images) --> go to page [2] >> previous / next
These are the lines I commented out. See what I noted below.
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
//commented out the line below so we don't get the row of page numbers.
// $result_final .= " [$i]";
$select_list .= "<option selected value=\"" . $_SERVER['PHP_SELF'] ."?cid=". $cid ."&page=". $i ."\"> ". $i ."</option>";
} else {
//Again, I commented out the line below so we don't get the row of page numbers.
// $result_final .= "\n<a href=\"".$_SERVER['PHP_SEL
$select_list .= "<option value=\"" . $_SERVER['PHP_SELF'] ."?cid=". $cid ."&page=". $i ."\"> ". $i ." </option>";
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
$result_final .= " [$i]";
$select_list .= "<option selected value=\"" . $_SERVER['PHP_SELF'] ."?cid=". $cid ."&page=". $i ."\">Page ". $i ."</option>";
} else {
if (($total_pages > 5)&&($i>2)) {
if ($i==3) {
$result_final .= "...";
}
} else {
$result_final .= "\n<a href=\"".$_SERVER['PHP_SEL F']."?cid= $cid&page= $i\" title='Page ".$i."'>$i</a>";
}
$select_list .= "<option value=\"" . $_SERVER['PHP_SELF'] ."?cid=". $cid ."&page=". $i ."\">Page ". $i ."</option>";
}
}
http://www.cafesong.com/Q_22470018.php
if(($page) == $i){
$result_final .= " [$i]";
$select_list .= "<option selected value=\"" . $_SERVER['PHP_SELF'] ."?cid=". $cid ."&page=". $i ."\">Page ". $i ."</option>";
} else {
if (($total_pages > 5)&&($i>2)) {
if ($i==3) {
$result_final .= "...";
}
} else {
$result_final .= "\n<a href=\"".$_SERVER['PHP_SEL
}
$select_list .= "<option value=\"" . $_SERVER['PHP_SELF'] ."?cid=". $cid ."&page=". $i ."\">Page ". $i ."</option>";
}
}
http://www.cafesong.com/Q_22470018.php
ASKER
Thank you rdivilbiss. Like I said though, I don't want to show the page numbers anymore. It's enough just saying "Showing Page: 1 of 10" and having the drop down menu next to it. Just trying to figure out how to move the coded section of "previous" and "next" so that it should follow AFTER the drop down menu. That seems like my biggest challenge at the moment. It's written in such a way, that I can't move the code that it should be displayed like:
page 1 of 63 (1000 images) --> go to page [2] >> previous / next
I have this part down fine. I worked out how to get the number of images and everything. Just want need to revise the code so the previous/next buttons are located AFTER the drop down menu (as shown above). Can't figure this out. I've tried everything it seems. Moving the code, etc. Nothing seems to work. If you can figure this out let me know. (Oh, and as you see above, I have this all in one line, not like your example on 2 lines) I have this working on my site, but I just need to fix this one issue. Let me know if you have any luck. Thanks so much for your help!
page 1 of 63 (1000 images) --> go to page [2] >> previous / next
I have this part down fine. I worked out how to get the number of images and everything. Just want need to revise the code so the previous/next buttons are located AFTER the drop down menu (as shown above). Can't figure this out. I've tried everything it seems. Moving the code, etc. Nothing seems to work. If you can figure this out let me know. (Oh, and as you see above, I have this all in one line, not like your example on 2 lines) I have this working on my site, but I just need to fix this one issue. Let me know if you have any luck. Thanks so much for your help!
Post your entire current code.
ASKER
O.k., here's my entire code, minus my intro table which you don't need. If you could figure this out, I'd be ever so grateful. Please let me know where the changes have been made as well. Minor adjustments have been made to this code since last we wrote, but nothing to effect what we're trying to do here. Everything's going o.k., except the 'next/prev' needs to be moved to follow the drop down menu like I said. Seems like it should'nt be too difficult, though I can't for the life of me figure out how to do this. If you get this down, the last thing I would as of you is if you could tell me how to repeat this entire line, "page 1 of 63 (1000 images) --> go to page [2] >> previous / next" so it can also appear at the top of my gallery as well as the bottom. THANKS!!
<?php
include("config.inc.php");
// initialization
$result_array = array();
$counter = 0;
$cid = (int)($_GET['cid']);
$pid = (int)($_GET['pid']);
// Category Listing
if(!$cid)
{
echo "Select a category";
} else if ($cid && !$_GET['thumb']) {
$result = mysql_query( "SELECT * FROM gallery_category WHERE parent_id = $cid" );
$num = 1;
echo "<table width='100%' border=1><tr>";
while( $row = mysql_fetch_array( $result ) )
{
$catname = $row['category_name'];
$catid = $row['category_id'];
echo "<td><a href='album.php?cid=".$cat id."&thumb =1&ocid=$c id'>".$cat name."</a> </td> ";
if ($num == '3') {
echo "</tr><tr>";
$num = 0;
}
$num ++;
}
echo "</tr></table>";
}
// Thumbnail Listing
else if( $cid && $_GET['thumb'] )
{
$number_of_thumbs_in_row = 4;
// If current page number, use it
// if not, set one!
if(!isset($_GET['page'])){
$page = 1;
} else {
$page = $_GET['page'];
}
// Define the number of results per page
$max_results = 12;
// Figure out the limit for the query based
// on the current page number.
$from = (($page * $max_results) - $max_results);
$result = @mysql_query( "SELECT photo_id,photo_caption,pho to_filenam e FROM gallery_photos WHERE photo_category='".addslash es($cid)." ' LIMIT $from, $max_results");
$nr = @mysql_num_rows( $result );
if( empty( $nr ) )
{
$result_final = "\t<tr><td><div align=\"center\"><strong>N o images in category found!</strong>
<br><br><font size=\"2\"><a href='album.php?cid=".$_GE T['ocid']. "'>Back to Photo Gallery Category List</a></font>
</div></td></tr>\n";
}
else
{
while( $row = mysql_fetch_array( $result ) )
{
//this is where we were able to add a caption/etc. under our thumbnail in the gallery.
$result_array[] = "<a href='album.php?cid=$cid&p id=".$row[ 0]."'><img src='".$images_dir."/tb_". $row[2]."' border='0' alt='".$row[1]."' /><br />".$row[0]."</a>";
}
mysql_free_result( $result );
$result = @mysql_query( "SELECT category_name FROM gallery_category WHERE category_id='".addslashes( $cid)."'" );
list($category_name) = mysql_fetch_array( $result );
mysql_free_result( $result );
$result2 = @mysql_query( "SELECT category_name FROM gallery_category WHERE category_id='".addslashes( $_GET['oci d'])."'" );
$row = mysql_fetch_object( $result2 );
$ocid = $row->category_name;
$result_final = "<tr><a href='album.php?cid=".$_GE T['ocid']. "'>$ocid</ a> > $category_name<br><br>";
//Think this might also be where you can add your caption below image?
foreach($result_array as $thumbnail_link)
{
if($counter == $number_of_thumbs_in_row)
{
$counter = 1;
$result_final .= $category_link."\n</tr>\n< tr>\n";
}
else
$counter++;
$result_final .= "\t<td><div align=\"center\">".$thumbn ail_link." </div></td >\n";
}
if($counter)
{
if($number_of_photos_in_ro w)
$result_final .= "\t<td colspan='".($number_of_thu mbs_in_row )."'></td> \n";
$result_final .= "</tr>\n";
// Figure out the total number of results in DB:
$total_results = mysql_result(mysql_query(" SELECT COUNT(*) as Num FROM gallery_photos WHERE photo_category=".addslashe s($cid)."" ),0);
$select_list = "<select size=\"1\" onchange=\"document.locati on=this[th is.selecte dIndex].va lue\">";
// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);
if ($total_pages >1)
{ // build links if more than one page
// Build Page Number Hyperlinks
$result_final .= "<tr><td colspan='".$number_of_thum bs_in_row. "'>page ".$page.' of '.$total_pages."";
// Build Previous Link
if($page > 1){
$prev = ($page - 1);
$result_final .= "\n<a href=\"".$_SERVER['PHP_SEL F']."?cid= $cid&ocid= ".$_GET['o cid']."&th umb=1&page =$prev\" title='Previous Page'><< previous</a>";
}
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
//commented out the line below so we don't get the row of page numbers.
// $result_final .= " [$i]";
$select_list .= "<option selected value=\"" . $_SERVER['PHP_SELF'] ."?cid=". $cid ."&ocid=".$_GET['ocid']."& thumb=1&pa ge=". $i ."\"> ". $i ."</option>";
} else {
//Again, I commented out the line below so we don't get the row of page numbers.
// $result_final .= "\n<a href=\"".$_SERVER['PHP_SEL F']."?cid= $cid&page= $i\" title='Page ".$i."'>$i</a>";
$select_list .= "<option value=\"" . $_SERVER['PHP_SELF'] ."?cid=". $cid ."&ocid=".$_GET['ocid']."& thumb=1&pa ge=". $i ."\"> ". $i ." </option>";
}
}
// Build Next Link
if($page < $total_pages){
$next = ($page + 1);
$result_final .= "\n<a href=\"".$_SERVER['PHP_SEL F']."?cid= $cid&ocid= ".$_GET['o cid']."&th umb=1&page =$next\" title='Next Page'>next >></a>";
}
//This is where we have our page links displayed.
$result_final .= " ($total_results images)"." > >go to page "."$select_list
</td></tr>";
$select_list .= " </select>" ;
}else{
$result_final .= "\n";
}
}
}
}
// Full Size View of Photo
if( $pid )
{
$result = mysql_query( "SELECT photo_caption,photo_filena me,photo_i d FROM gallery_photos WHERE photo_id='".addslashes($pi d)."'" );
list($photo_caption, $photo_filename, $photo_id, $photographer) = mysql_fetch_array( $result );
$nr = mysql_num_rows( $result );
mysql_free_result( $result );
if( empty( $nr ) )
{
$result_final = "\t<tr><td>No Photo found</td></tr>\n";
}
else
{
$result = mysql_query( "SELECT category_name FROM gallery_category WHERE category_id='".addslashes( $cid)."'" );
list($category_name) = mysql_fetch_array( $result );
mysql_free_result( $result );
$result_final .= "<tr border='0'>
<a href='album.php'>Categorie s</a> >
<a href='album.php?cid=$cid'> $category_ name</a></ td>";
//This is where the full size image is displayed with the text below it.
$result_final .= "<p><tr>\n\t<td align='left'>
<img src='".$images_dir."/".$ph oto_filena me."' border='0' alt='".$photo_caption."' />
<td align='left' valign='top' border='0' >
$photo_id<br />
Location: $location<br />
$photo_caption<br />
$photo_category Photographer: $photographer<br />
Date Photographed: $date_photographed<br />
File Size Availability: $file_size<br />
Keywords: $keywords <br />
Model Release: $model_release<br />
Property Release: $property_release
</td>
</tr>";
}
}
// Final Output
echo <<<__HTML_END
<html>
<head>
</head>
<body>
<table width='98%' cellspacing='0' cellpadding='7' bgcolor='#666666' border='1' bordercolor='#333333' valign='top' align='left'>
$result_final
</table>
</body>
</html>
__HTML_END;
?>
<?php
include("config.inc.php");
// initialization
$result_array = array();
$counter = 0;
$cid = (int)($_GET['cid']);
$pid = (int)($_GET['pid']);
// Category Listing
if(!$cid)
{
echo "Select a category";
} else if ($cid && !$_GET['thumb']) {
$result = mysql_query( "SELECT * FROM gallery_category WHERE parent_id = $cid" );
$num = 1;
echo "<table width='100%' border=1><tr>";
while( $row = mysql_fetch_array( $result ) )
{
$catname = $row['category_name'];
$catid = $row['category_id'];
echo "<td><a href='album.php?cid=".$cat
if ($num == '3') {
echo "</tr><tr>";
$num = 0;
}
$num ++;
}
echo "</tr></table>";
}
// Thumbnail Listing
else if( $cid && $_GET['thumb'] )
{
$number_of_thumbs_in_row = 4;
// If current page number, use it
// if not, set one!
if(!isset($_GET['page'])){
$page = 1;
} else {
$page = $_GET['page'];
}
// Define the number of results per page
$max_results = 12;
// Figure out the limit for the query based
// on the current page number.
$from = (($page * $max_results) - $max_results);
$result = @mysql_query( "SELECT photo_id,photo_caption,pho
$nr = @mysql_num_rows( $result );
if( empty( $nr ) )
{
$result_final = "\t<tr><td><div align=\"center\"><strong>N
<br><br><font size=\"2\"><a href='album.php?cid=".$_GE
</div></td></tr>\n";
}
else
{
while( $row = mysql_fetch_array( $result ) )
{
//this is where we were able to add a caption/etc. under our thumbnail in the gallery.
$result_array[] = "<a href='album.php?cid=$cid&p
}
mysql_free_result( $result );
$result = @mysql_query( "SELECT category_name FROM gallery_category WHERE category_id='".addslashes(
list($category_name) = mysql_fetch_array( $result );
mysql_free_result( $result );
$result2 = @mysql_query( "SELECT category_name FROM gallery_category WHERE category_id='".addslashes(
$row = mysql_fetch_object( $result2 );
$ocid = $row->category_name;
$result_final = "<tr><a href='album.php?cid=".$_GE
//Think this might also be where you can add your caption below image?
foreach($result_array as $thumbnail_link)
{
if($counter == $number_of_thumbs_in_row)
{
$counter = 1;
$result_final .= $category_link."\n</tr>\n<
}
else
$counter++;
$result_final .= "\t<td><div align=\"center\">".$thumbn
}
if($counter)
{
if($number_of_photos_in_ro
$result_final .= "\t<td colspan='".($number_of_thu
$result_final .= "</tr>\n";
// Figure out the total number of results in DB:
$total_results = mysql_result(mysql_query("
$select_list = "<select size=\"1\" onchange=\"document.locati
// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);
if ($total_pages >1)
{ // build links if more than one page
// Build Page Number Hyperlinks
$result_final .= "<tr><td colspan='".$number_of_thum
// Build Previous Link
if($page > 1){
$prev = ($page - 1);
$result_final .= "\n<a href=\"".$_SERVER['PHP_SEL
}
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
//commented out the line below so we don't get the row of page numbers.
// $result_final .= " [$i]";
$select_list .= "<option selected value=\"" . $_SERVER['PHP_SELF'] ."?cid=". $cid ."&ocid=".$_GET['ocid']."&
} else {
//Again, I commented out the line below so we don't get the row of page numbers.
// $result_final .= "\n<a href=\"".$_SERVER['PHP_SEL
$select_list .= "<option value=\"" . $_SERVER['PHP_SELF'] ."?cid=". $cid ."&ocid=".$_GET['ocid']."&
}
}
// Build Next Link
if($page < $total_pages){
$next = ($page + 1);
$result_final .= "\n<a href=\"".$_SERVER['PHP_SEL
}
//This is where we have our page links displayed.
$result_final .= " ($total_results images)"." >
</td></tr>";
$select_list .= " </select>" ;
}else{
$result_final .= "\n";
}
}
}
}
// Full Size View of Photo
if( $pid )
{
$result = mysql_query( "SELECT photo_caption,photo_filena
list($photo_caption, $photo_filename, $photo_id, $photographer) = mysql_fetch_array( $result );
$nr = mysql_num_rows( $result );
mysql_free_result( $result );
if( empty( $nr ) )
{
$result_final = "\t<tr><td>No Photo found</td></tr>\n";
}
else
{
$result = mysql_query( "SELECT category_name FROM gallery_category WHERE category_id='".addslashes(
list($category_name) = mysql_fetch_array( $result );
mysql_free_result( $result );
$result_final .= "<tr border='0'>
<a href='album.php'>Categorie
<a href='album.php?cid=$cid'>
//This is where the full size image is displayed with the text below it.
$result_final .= "<p><tr>\n\t<td align='left'>
<img src='".$images_dir."/".$ph
<td align='left' valign='top' border='0' >
$photo_id<br />
Location: $location<br />
$photo_caption<br />
$photo_category Photographer: $photographer<br />
Date Photographed: $date_photographed<br />
File Size Availability: $file_size<br />
Keywords: $keywords <br />
Model Release: $model_release<br />
Property Release: $property_release
</td>
</tr>";
}
}
// Final Output
echo <<<__HTML_END
<html>
<head>
</head>
<body>
<table width='98%' cellspacing='0' cellpadding='7' bgcolor='#666666' border='1' bordercolor='#333333' valign='top' align='left'>
$result_final
</table>
</body>
</html>
__HTML_END;
?>
It will take me a bit to get back to this.
ASKER
I appreciate your time and efforts. How much time do you need? Is it because of the difficulty involved, or something else personal? When should I expect to hear from you? A few days? A week?
Thanks again. You definitely deserve those 500 points.
Thanks again. You definitely deserve those 500 points.
I am opening a restaurant for my wife, and spent most of the day with the leasing agent, property manager and construction contractor. That and a zillion detailed measurements to make sure I'm not getting billed for more space than I'm leasing has given me a large headache, which I'm trying to cure with wine and therefore I am in no condition (or hope to be soon) to write coherent code.
I should have something in the morning.
I should have something in the morning.
ASKER
Wow, I wish you luck with that. Sounds exciting. I'm sure you'll get all the details worked out with them. Congrats! I understand how writing code could be that last thing on your mind. I appreciate your time.
I didn't debug this, but it illustrates what you want to do.
Don't build every think in the $results_final.
Make variables for each portion of the string, $select_list, $nextLink, $prevLink, $pageOfPages, $pageNoLinks, etc. etc.
Now you have the flexibility to reorder how you display those items in the row.
// Figure out the total number of results in DB:
$total_results = mysql_result(mysql_query(" SELECT COUNT(*) as Num FROM gallery_photos WHERE photo_category=".addslashe s($cid)."" ),0);
$select_list = "<select size=\"1\" onchange=\"document.locati on=this[th is.selecte dIndex].va lue\">";
// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);
if ($total_pages >1)
{ // build links if more than one page
// Build Page Number Hyperlinks
$result_final .= "<tr><td colspan='".$number_of_thum bs_in_row. "'>";
$pageOfPages = page ".$page." of ".$total_pages."";
/ Build Previous Link
if($page > 1){
$prev = ($page - 1);
$prevLink .= "\n<a href=\"".$_SERVER['PHP_SEL F']."?cid= $cid&ocid= ".$_GET['o cid']."&th umb=1&page =$prev\" title='Previous Page'><< previous</a>";
}
$pageNoLinks="";
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
//commented out the line below so we don't get the row of page numbers.
$pageNoLinks .= " [$i]";
$select_list .= "<option selected value=\"" . $_SERVER['PHP_SELF'] ."?cid=". $cid ."&ocid=".$_GET['ocid']."& thumb=1&pa ge=". $i ."\"> ". $i ."</option>";
} else {
//Again, I commented out the line below so we don't get the row of page numbers.
$pageNoLinks .= "\n<a href=\"".$_SERVER['PHP_SEL F']."?cid= $cid&page= $i\" title='Page ".$i."'>$i</a>";
$select_list .= "<option value=\"" . $_SERVER['PHP_SELF'] ."?cid=". $cid ."&ocid=".$_GET['ocid']."& thumb=1&pa ge=". $i ."\"> ". $i ." </option>";
}
}
// Build Next Link
if($page < $total_pages){
$next = ($page + 1);
$nextLink = "\n<a href=\"".$_SERVER['PHP_SEL F']."?cid= $cid&ocid= ".$_GET['o cid']."&th umb=1&page =$next\" title='Next Page'>next >></a>";
}
//Put the string together in ant order we want.
$result_final .= $pageOfPages ." ". "(" . $total_results ."images)" . " >>go to page " . $select_list;
$result_final .= " " . $prevLink ." / ". $nextLink;
$result_final .= </td></tr>";
Don't build every think in the $results_final.
Make variables for each portion of the string, $select_list, $nextLink, $prevLink, $pageOfPages, $pageNoLinks, etc. etc.
Now you have the flexibility to reorder how you display those items in the row.
// Figure out the total number of results in DB:
$total_results = mysql_result(mysql_query("
$select_list = "<select size=\"1\" onchange=\"document.locati
// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);
if ($total_pages >1)
{ // build links if more than one page
// Build Page Number Hyperlinks
$result_final .= "<tr><td colspan='".$number_of_thum
$pageOfPages = page ".$page." of ".$total_pages."";
/ Build Previous Link
if($page > 1){
$prev = ($page - 1);
$prevLink .= "\n<a href=\"".$_SERVER['PHP_SEL
}
$pageNoLinks="";
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
//commented out the line below so we don't get the row of page numbers.
$pageNoLinks .= " [$i]";
$select_list .= "<option selected value=\"" . $_SERVER['PHP_SELF'] ."?cid=". $cid ."&ocid=".$_GET['ocid']."&
} else {
//Again, I commented out the line below so we don't get the row of page numbers.
$pageNoLinks .= "\n<a href=\"".$_SERVER['PHP_SEL
$select_list .= "<option value=\"" . $_SERVER['PHP_SELF'] ."?cid=". $cid ."&ocid=".$_GET['ocid']."&
}
}
// Build Next Link
if($page < $total_pages){
$next = ($page + 1);
$nextLink = "\n<a href=\"".$_SERVER['PHP_SEL
}
//Put the string together in ant order we want.
$result_final .= $pageOfPages ." ". "(" . $total_results ."images)" . " >>go to page " . $select_list;
$result_final .= " " . $prevLink ." / ". $nextLink;
$result_final .= </td></tr>";
ASKER
Yes, I thought that would be a problem for us. Unfortunately being a newbie to PHP, I had to obtain this code from a tutorial. So I'm working with it as best I can, making my own modifications. I saw they kept using the same variable name over and over, which is confusing. Thanks, I'll try out the code and get back to you with the results no later than tomorrow.
ASKER
I ran your script above and got parse errors. After pasting the code, I could tell that something was off due to the colors of the code not coming in correctly. I'm using Dreamweaver, so it helps for me to see when a color is off, most likely something is wrong. Anyways, I run your script as is and I get a parse error at line 187:
Parse error: parse error, unexpected '\"' in /homepages/40/my url is here/album.php on line 187
So I checked out the code and thought that by deleting the second quotes at the end of statement would correct the code that follows. I took the second quote off the end of line 187 so it reads:
LINE 185: // Build Page Number Hyperlinks
LINE 186: $result_final .= "<tr><td colspan='".$number_of_thum bs_in_row. "'>";
LINE: 187: $pageOfPages = page ".$page." of ".$total_pages.";
(This may be completely wrong, but I wasn't sure what the error was)
Anyways, the rest of the code looked liked it recolored itself correctly, except for line 219:
LINE 216: //Put the string together in ant order we want.
LINE 217: $result_final .= $pageOfPages ." ". "(" . $total_results ."images)" . " >>go to page " . $select_list;
LINE 218: $result_final .= " " . $prevLink ." / ". $nextLink;
LINE 219: $result_final .= </td></tr>";
The closing tags for the column and row are colored wrong. Something's affecting it. If I ADD another quote at the end of the liine, before the semicolon, the code that follows this line becomes colored correctly, though these two ending tags are still incorrect. Something's wrong.
LINE 219: $result_final .= </td></tr>"";
Don't mean to confuse you, but thought these clues might be able to help you out. Sorry to be such a bother, but I know we can figure this out. Any thoughts?
Parse error: parse error, unexpected '\"' in /homepages/40/my url is here/album.php on line 187
So I checked out the code and thought that by deleting the second quotes at the end of statement would correct the code that follows. I took the second quote off the end of line 187 so it reads:
LINE 185: // Build Page Number Hyperlinks
LINE 186: $result_final .= "<tr><td colspan='".$number_of_thum
LINE: 187: $pageOfPages = page ".$page." of ".$total_pages.";
(This may be completely wrong, but I wasn't sure what the error was)
Anyways, the rest of the code looked liked it recolored itself correctly, except for line 219:
LINE 216: //Put the string together in ant order we want.
LINE 217: $result_final .= $pageOfPages ." ". "(" . $total_results ."images)" . " >>go to page " . $select_list;
LINE 218: $result_final .= " " . $prevLink ." / ". $nextLink;
LINE 219: $result_final .= </td></tr>";
The closing tags for the column and row are colored wrong. Something's affecting it. If I ADD another quote at the end of the liine, before the semicolon, the code that follows this line becomes colored correctly, though these two ending tags are still incorrect. Something's wrong.
LINE 219: $result_final .= </td></tr>"";
Don't mean to confuse you, but thought these clues might be able to help you out. Sorry to be such a bother, but I know we can figure this out. Any thoughts?
ASKER
Can you help me debug this please? Last issue, promise.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Working VERY NICELY. Thanks so much for all your hard work. I greatly appreciate it. I hope everything works out with your wife's new restaurant. Best wishes. I gave you the highest grading.
By the way, I don't know if you feel like helping me out with another issue, sought of complicated. ANOTHER 500 POINTS!! It's been posted for over a week and I only got 1 response. I'm having issues with my gallery regarding uploading images larger in size. They do upload, but the thumbnails aren't being created in my directory, and when you do click on the full size image in the browser, it comes in HUGE. Mostly happening to images that come directly from a digital camera. Don't kow if it's my php.ini file? See this link on Experts Exchange.
https://www.experts-exchange.com/questions/22470080/Gallery-problem-with-large-size-photos.html
SUBJECT LINE IS: Gallery problem with large size photos
By the way, I don't know if you feel like helping me out with another issue, sought of complicated. ANOTHER 500 POINTS!! It's been posted for over a week and I only got 1 response. I'm having issues with my gallery regarding uploading images larger in size. They do upload, but the thumbnails aren't being created in my directory, and when you do click on the full size image in the browser, it comes in HUGE. Mostly happening to images that come directly from a digital camera. Don't kow if it's my php.ini file? See this link on Experts Exchange.
https://www.experts-exchange.com/questions/22470080/Gallery-problem-with-large-size-photos.html
SUBJECT LINE IS: Gallery problem with large size photos
http://www.plus2net.com/php_tutorial/php_drop_down_list.php
https://www.experts-exchange.com/questions/20338219/Displaying-Records-in-Multiple-pages-Using-Combo-Box.html