Page 1 of 1

Help on Guestbook Page Number

Posted: Thu Sep 17, 2009 8:47 pm
by 222222
I've got a guestbook that installed by my friend several years ago and there are 70 pages of messages.

The Page Nos are shown in a single line that stretch the page horizontally across the browser (see this link Guestbook).
I 've tried many times but was not able to separate the Page Nos into 2 or 3 rows.

I am not familiar with php. Could someone help me out? Thank you so much.

Re: Help on Guestbook Page Number

Posted: Fri Sep 18, 2009 1:52 am
by cpetercarter
This is an html problem, not a php problem.

I have looked at the html for your web page. The page numbers are in a single table row (<tr>...</tr>), each number in its own table data cell (<td>..</td>). This will display as a single line of numbers stretching off to the right of the browser.

Possible solutions :

Don't put the page numbers in separate <td> cells. Instead construct a string which looks something like this - "Page: 1 2 3 4 .........etc" and put it in a single <td> cell. If you find that you still have problems, try setting a "width" or "max-width" property for the table.

Or, use several table rows. Put, for example, pages 1 to 20 in the first row, 21 to 40 in the next and so on.

Incidentally, the html for your web page is not good. The www markup validator cannot even parse the page. Styling is mixed in with structure, and there are some basic html errors (there is a stray </td> immediately after the line with the page numbers, for example.) If you have an opportunity to rewrite the html, and put the styling into a separate style sheet, it would be much easier to deal with problems.

Re: Help on Guestbook Page Number

Posted: Fri Sep 18, 2009 3:57 am
by davidcroda
insert the following code where you would like it to begin a new row, immediately after the </td> tag

Code: Select all

</tr><tr>
this will end the current row and start a new one

Re: Help on Guestbook Page Number

Posted: Fri Sep 18, 2009 4:43 am
by jackpf
In the loop which is generating the page numbers, you can check if the counter is divisible by however many pages you want per row.

If so, display a closing </tr> tag and an opening <tr> tag to start a new row.

Example:

Code: Select all

echo '<table><tr>';
for($counter = 0; $fetch = mysql_fetch_array($your_page_query); $counter++)
{
    echo '<td>Your stuff</td>'; 
 
    if($counter % 4 == 0)
    {
        echo '</tr><tr>';
    }
}
echo '</tr></table>';

Re: Help on Guestbook Page Number

Posted: Fri Sep 18, 2009 5:31 am
by turbolemon
Alternately, you could use an inline'd list, fix the width of the container, and have the page numbers flow as required. The same could be achieved by not using table cells and just have the links for the page numbers in a <div> or <p>.

Re: Help on Guestbook Page Number

Posted: Fri Sep 18, 2009 12:21 pm
by 222222
Dear jackpf ,

I am not familiar with php at all. I've extracted a section that might be relevant to what you were talking about. Grateful if you could show where to add the closing </tr> tag and an opening <tr> tag. Thank you so much.

Code: Select all

function navigation($pagenumber, $page) {
echo "<table width='700' align='center' valignn='bottom' border='0' cellspacing='0' cellpadding='5' style='margin-top:0;margin-left:0;margin-right:0;margin-bottom:0'>
          <tr>
        <td>
        <table><tr>
 
            <td width='20' align='left'><font style='font-family:verdana;font-size:10pt;color:white'>Page : </font></td>";
 
$udah_prev = 0;
$udah_next = 0;
 
 
if ($pagenumber == 1) { 
   echo "<td width='20' align='left'><font style='font-family:verdana;font-size:10pt;color:FFCCCC;font-weight:bold'>1</font></td>";
   } else {
   if (($udah_prev == 0) and (($page-1) >0)) {
      $hal = $page - 1;
      $udah_prev = 1;
      echo " <td width='20' align='left'><a href='guestbook.php?page=$hal'><img src='/apps/image/left_arrow1.jpg' border='0'></a></td> ";
   }
   for ($i=1; $i <= $pagenumber; $i++) {
      if ($i == $page) { 
         echo " <td width='20' align='left'><font style='font-family:verdana;font-size:12pt;color:F5C3C3;font-weight:bold'>$page</font></td> "; 
     } else { 
     echo " <td width='20' align='left'><a href='guestbook.php?page=$i'><font style='font-family:verdana;font-size:10pt;color:white;text-decoration:none'>$i</font></a></td> "; 
      }
   }
   if (($udah_next == 0) and (($page + 1) <= $pagenumber)) {
      $hal = $page + 1;
      $udah_next = 1;
      echo " <td width='20' align='left'><a href='guestbook.php?page=$hal'><img src='/apps/image/right_arrow1.jpg' border='0'></a></td> ";
   }
} 
 
echo "
      </tr></table></td>
          </tr>
        </table>
";
}

Re: Help on Guestbook Page Number

Posted: Fri Sep 18, 2009 12:57 pm
by jackpf
You see this for loop:

Code: Select all

for ($i=1; $i <= $pagenumber; $i++)
You'll need to close and open a <tr> tag in there.

But if you're not familiar with PHP, maybe you should just do as turbolemon suggested.