A question about layout

A

Anonymous

Guest
Hello,

The following is the code I am working on. It works fine but puts Prev, the number of pages and next in one single cel. I am trying to put them in separate cell. ie one cell for Prev, one for page1, one for page2 etc...

Any idea how I can achieve this? Thanks a million.
Jacques
<?
} // while
print "<table width=500 align=center><tr>\n";
print "<font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"2\">\n";
$prevoffset=$offset-$products_per_page;
if ($prevoffset >= 0) {
print "<td><a href=\"$PHP_SELF?offset=$prevoffset\">PREV</a></td>   \n";
} else {
print "PREV   \n";
}

// calculate number of pages needing links
$pages=intval($numrows/$products_per_page);

// $pages now contains int of pages needed unless there is a remainder from division
if ($numrows%$products_per_page) {
// has remainder so add one page
$pages++;
}

for ($i=1;$i<=$pages;$i++) { // loop thru
$newoffset=$products_per_page*($i-1);
if($newoffset==$offset) {
print "<b>$i</b>   \n";
} else {
print "<a href=\"$PHP_SELF?offset=$newoffset\">$i</a>   \n";
}
}

// check to see if last page
if (!(($offset/$products_per_page)==$pages) && $pages!=1) {
// not last page so give NEXT link
$newoffset=$offset+$products_per_page;
if ($newoffset < ($numrows+1)) {
print "<a href=\"$PHP_SELF?offset=$newoffset\">NEXT</a><p>\n";
} else {
print "NEXT  <p>\n";
}

} else {
print "NEXT  <p>\n";
}

print "</td></tr><tr><td align=left>\n";
print "</td><td align=right></tr></table>\n";
?>
 
Just had a quick look and the problem seems to be your code here:
Code:
for ($i=1;$i<=$pages;$i++) { // loop thru 
$newoffset=$products_per_page*($i-1); 
if($newoffset==$offset) { 
print "<b>$i</b>   \n"; 
} else { 
print "<a href=\"$PHP_SELF?offset=$newoffset\">$i</a>   \n"; 
} 
}
You're outputting numbers on their own, and not within a cell.
try print "<td><b>$i</b></td>\n";
 
Thank you Jay.

Your help has improved the layout. I have one more question

This line
print "<td class=sidemenu onMouseOver='mOvr(this,sideover);' onMouseOut='mOut(this,sideover);' bgcolor=#777777 width=28 align=center><b>$i</b></td>\n";

uses a style defined for all the pages. Is php able to read it? If yes, then there is something wrong with what I have, even though it works well outsite of php/
 
Jacques said:
I have one more question

This line
print "<td class=sidemenu onMouseOver='mOvr(this,sideover);' onMouseOut='mOut(this,sideover);' bgcolor=#777777 width=28 align=center><b>$i</b></td>\n";

uses a style defined for all the pages. Is php able to read it? If yes, then there is something wrong with what I have, even though it works well outsite of php/
"class=sidemenu" is html and is not related to php.
with php you create pages wich are showed by the browser.
To make sure the browser "knows" the style you want to use, you either have to include it in the file itself, or link to an external stylesheet.

This probably doesn't answer you're question, but then again, I didn't get you're actual problem. Hope this helps.

Greetz Daan
 
Jacques said:
Thank you Jay.

Your help has improved the layout. I have one more question

This line
print "<td class=sidemenu onMouseOver='mOvr(this,sideover);' onMouseOut='mOut(this,sideover);' bgcolor=#777777 width=28 align=center><b>$i</b></td>\n";

uses a style defined for all the pages. Is php able to read it? If yes, then there is something wrong with what I have, even though it works well outsite of php/
As DoppyNL has said, PHP doesn't understand or interpret HTML, it merely outputs it. The browser reads the HTML and interprets it. I don't what you're asking, except that will PHP find the $i within that string and replae it with the appropriate value? In THAT string, yes it will due to many reasons being present. The string is enclosed in double (not single) quotes, and the $i cannot be confused with anything else. If you wanted an s on the end of the $i value, your code would look something like "...$is...." but PHP would read that as an $is variable which doesn't exist. It's always safest however to put your variables outside the quotes:
$string = "this is the ".$num." line";
 
Thank you guys. There is so much to learn. I am doing it from books and looking at freecodes that I collect throughout the websites. Not always easy at the early stage to know when a code is well written or not. Guess this will come with experience. I am having a great time though.

I hope you won't mind if I ask for some guidance here and there during my journey.
 
Back
Top