Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

A question about layout

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

A question about layout

Postby Jacques » Fri Oct 18, 2002 8:12 am

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> &nbsp; \n";
} else {
print "PREV &nbsp; \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> &nbsp; \n";
} else {
print "<a href=\"$PHP_SELF?offset=$newoffset\">$i</a> &nbsp; \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 &nbsp;<p>\n";
}

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

print "</td></tr><tr><td align=left>\n";
print "</td><td align=right></tr></table>\n";
?>
Jacques
New php-forum User
New php-forum User
 
Posts: 10
Joined: Fri Oct 18, 2002 8:07 am

Postby Jay » Fri Oct 18, 2002 8:35 am

Just had a quick look and the problem seems to be your code here:
Code: Select all
for ($i=1;$i<=$pages;$i++) { // loop thru
$newoffset=$products_per_page*($i-1);
if($newoffset==$offset) {
print "<b>$i</b> &nbsp; \n";
} else {
print "<a href=\"$PHP_SELF?offset=$newoffset\">$i</a> &nbsp; \n";
}
}

You're outputting numbers on their own, and not within a cell.
try print "<td><b>$i</b></td>\n";
Jay
 

Layout

Postby Jacques » Fri Oct 18, 2002 11:14 am

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
New php-forum User
New php-forum User
 
Posts: 10
Joined: Fri Oct 18, 2002 8:07 am

Re: Layout

Postby DoppyNL » Fri Oct 18, 2002 11:43 am

Jacques wrote: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
DoppyNL
 

Re: Layout

Postby Jay » Fri Oct 18, 2002 2:26 pm

Jacques wrote: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";
Jay
 

So much to learn

Postby Jacques » Mon Oct 21, 2002 6:40 am

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.
Jacques
New php-forum User
New php-forum User
 
Posts: 10
Joined: Fri Oct 18, 2002 8:07 am

Re: So much to learn

Postby Jay » Mon Oct 21, 2002 12:11 pm

Jacques wrote:I hope you won't mind if I ask for some guidance here and there during my journey.

That's what we're here for!
Jay
 


Return to PHP coding => General

Who is online

Users browsing this forum: Google [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron