473,386 Members | 1,758 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Best Practice for layout items at one page

Hello all,

I am looking for a neat and best practice way to layout a number of
items (say, no more than 16 records) in one page, fill in a 4x4 grid.
The most clear way is using <tableto display HTML. But the number of
records is variable, so how i can program to render HTML code
correctly? For example, if we have 5 records, it should appear 4 items
at first row, and 1 item at second row. so on.
I am new to PHP and PHP template, so i wanna start from this point to
get more understand of PHP. I have also read book <Programming PHPbut
there is no obvious answer of this.

$result = mysql_query ("SELECT * FROM item", $connection);
........

Expecting your great reponse. Thanks!
Regards,
David

Dec 22 '06 #1
2 1472
da******@gmail.com wrote:
Hello all,

I am looking for a neat and best practice way to layout a number of
items (say, no more than 16 records) in one page, fill in a 4x4 grid.
The most clear way is using <tableto display HTML. But the number of
records is variable, so how i can program to render HTML code
correctly? For example, if we have 5 records, it should appear 4 items
at first row, and 1 item at second row. so on.
I am new to PHP and PHP template, so i wanna start from this point to
get more understand of PHP. I have also read book <Programming PHPbut
there is no obvious answer of this.

$result = mysql_query ("SELECT * FROM item", $connection);
.......

Expecting your great reponse. Thanks!
Regards,
David
Don't know if it would be "best practice", but this would work-

$result = mysql_query ("SELECT * FROM item", $connection);
$num_results = mysql_num_rows($result);
$num_rows = ceil($num_results/4);

for( $row=0; $row<$num_rows; $row++ ){
echo '<tr>';
for( $col=0; $col<4; $col++ ) {
$data = @mysql_fetch_assoc($result);
echo '<td>';
.....
do some stuff with the data
.....
echo '&nbsp;</td>'; // the &nbsp; is important for // when no
data is returned
}
echo '</tr>';
}
Dec 22 '06 #2
Great! That's really what i am looking for and it actually works!

But not enough :-) If i am understand correctly, this is some PHP code
which bind in HTML, if the HTML will be change, the PHP code also need
to be change to output HTML.
So, is there a neat way to write in using 'template'? Let me write some
pesduocode to explain what i am looking for:
<TR php:if (count%4==0)>
<TD php:if (result[count])>
<A href=php:(result[count]["field_image1_url"])></A>


"Cliff Smith wrote:
Don't know if it would be "best practice", but this would work-

$result = mysql_query ("SELECT * FROM item", $connection);
$num_results = mysql_num_rows($result);
$num_rows = ceil($num_results/4);

for( $row=0; $row<$num_rows; $row++ ){
echo '<tr>';
for( $col=0; $col<4; $col++ ) {
$data = @mysql_fetch_assoc($result);
echo '<td>';
.....
do some stuff with the data
.....
echo '&nbsp;</td>'; // the &nbsp; is important for //
Dec 22 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

24
by: delerious | last post by:
Hi, I am designing a web site that will that showcase a bunch of vacation pictures. It will have a banner and a navigation menu (consisting of 13 rectangular images that can be clicked). I am...
131
by: Peter Foti | last post by:
Simple question... which is better to use for defining font sizes and why? px and em seem to be the leading candidates. I know what the general answer is going to be, but I'm hoping to ultimately...
7
by: Hostile17 | last post by:
I'm trying to arrive at a kind of "industry standard" or "best practice" approach to CSS for a policy document aimed at developers, but not necessarily very experienced developers. What does the...
47
by: Neal | last post by:
Patrick Griffiths weighs in on the CSS vs table layout debate in his blog entry "Tables my ass" - http://www.htmldog.com/ptg/archives/000049.php . A quite good article.
4
by: Will Hartung | last post by:
The designers have handed me a page that has 5 different blocks on it in the center column (in a typical 3 column layout with page spanning headers and footers). The blocks have elaborate...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
6
by: Sandy | last post by:
Hello - I have a book that illustrates pulling menu items from a Sql Server table into an ascx via a stored procedure. Is this something that is done in the real world? I do like the effect...
9
by: Gummy | last post by:
Hello, I created a user control that has a ListBox and a RadioButtonList (and other stuff). The idea is that I put the user control on the ASPX page multiple times and each user control will...
13
by: Justin.Voelker | last post by:
Hello Everyone: I am in search of an easier way to develop pages. My most current website, www.Base2WebDesign.com, has the exact same layout throughout the entire site. Right now I use a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.