Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > Is this good code? Good practice advice needed...

Reply
Thread Tools

Is this good code? Good practice advice needed...

 
 
SM
Guest
Posts: n/a
 
      11-08-2007
Hello,

I've created a gallery of photos in php. The model is very simple:
Album/subalbum/photos.
If the user clicks on an album, a bunch of subalbums appear. And if
the user selects one of the subalbum, a gallery of photos appear.

The gallery of photos appear right beneath the subalbum list item
selected by the user. I've tested everything and the result is prety
cool.

Now, because im trying to be compiant with HTML/XHTML, and mostly
because im trying to create good code, i was wondering if the piece of
code is OK.

Even though everything works ok, i was wondering for example if i can
insert a <div> between an <li>.
Is it better to put an <a> inside a <ul><li> when im constructiing a
list?


This is a sample of the code. Notice the insertion of the gallery
beneath the <li> selected by the user.
....
<!-- CONTENT_RIGHT -->
<div id="content_right">
<ul>
<li><a href="#">Gallery One</a></li>
<li><a href="#">Sky</a></li>
<li><a href="#">Hello World</a></li>
<li><a href="#">Tribute</a></li>
<div id="thumbnail">
<a href="#"><img src="images/photography/1.jpg" /></a>
<a href="#"><img src="images/photography/2.jpg" /></a>
<a href="#"><img src="images/photography/3.jpg" /></a>
<a href="#"><img src="images/photography/4.jpg" /></a>
<a href="#"><img src="images/photography/5.jpg" /></a>
</div>

<li><a href="#">Cloud 9</a></li>
<li><a href="#">The End</a></li>
</ul>
</div>
......

Is this good code?

Thanks
Marco

 
Reply With Quote
 
 
 
 
Adrienne Boswell
Guest
Posts: n/a
 
      11-08-2007
On Nov 8, 12:01 pm, SM <servandomont...@gmail.com> wrote:
> Hello,
>
> I've created a gallery of photos in php. The model is very simple:
> Album/subalbum/photos.
> If the user clicks on an album, a bunch of subalbums appear. And if
> the user selects one of the subalbum, a gallery of photos appear.
>
> The gallery of photos appear right beneath the subalbum list item
> selected by the user. I've tested everything and the result is prety
> cool.
>
> Now, because im trying to be compiant with HTML/XHTML, and mostly
> because im trying to create good code, i was wondering if the piece of
> code is OK.
>
> Even though everything works ok, i was wondering for example if i can
> insert a <div> between an <li>.
> Is it better to put an <a> inside a <ul><li> when im constructiing a
> list?
>
> This is a sample of the code. Notice the insertion of the gallery
> beneath the <li> selected by the user.
> ...
> <!-- CONTENT_RIGHT -->
> <div id="content_right">
> <ul>
> <li><a href="#">Gallery One</a></li>
> <li><a href="#">Sky</a></li>
> <li><a href="#">Hello World</a></li>
> <li><a href="#">Tribute</a></li>
> <div id="thumbnail">
> <a href="#"><img src="images/photography/1.jpg" /></a>
> <a href="#"><img src="images/photography/2.jpg" /></a>
> <a href="#"><img src="images/photography/3.jpg" /></a>
> <a href="#"><img src="images/photography/4.jpg" /></a>
> <a href="#"><img src="images/photography/5.jpg" /></a>
> </div>
>
> <li><a href="#">Cloud 9</a></li>
> <li><a href="#">The End</a></li>
> </ul>
> </div>
> .....
>
> Is this good code?
>
> Thanks
> Marco


A URL would be more helpful. But the answer your question, run the
page through the validator and see what it comes up with. Hint: a UL
element can only contain LI elements.


 
Reply With Quote
 
 
 
 
SM
Guest
Posts: n/a
 
      11-08-2007
On Nov 8, 3:28 pm, Adrienne Boswell <arb...@yahoo.com> wrote:
> On Nov 8, 12:01 pm, SM <servandomont...@gmail.com> wrote:
>
>
>
> > Hello,

>
> > I've created a gallery of photos in php. The model is very simple:
> > Album/subalbum/photos.
> > If the user clicks on an album, a bunch of subalbums appear. And if
> > the user selects one of the subalbum, a gallery of photos appear.

>
> > The gallery of photos appear right beneath the subalbum list item
> > selected by the user. I've tested everything and the result is prety
> > cool.

>
> > Now, because im trying to be compiant with HTML/XHTML, and mostly
> > because im trying to create good code, i was wondering if the piece of
> > code is OK.

>
> > Even though everything works ok, i was wondering for example if i can
> > insert a <div> between an <li>.
> > Is it better to put an <a> inside a <ul><li> when im constructiing a
> > list?

>
> > This is a sample of the code. Notice the insertion of the gallery
> > beneath the <li> selected by the user.
> > ...
> > <!-- CONTENT_RIGHT -->
> > <div id="content_right">
> > <ul>
> > <li><a href="#">Gallery One</a></li>
> > <li><a href="#">Sky</a></li>
> > <li><a href="#">Hello World</a></li>
> > <li><a href="#">Tribute</a></li>
> > <div id="thumbnail">
> > <a href="#"><img src="images/photography/1.jpg" /></a>
> > <a href="#"><img src="images/photography/2.jpg" /></a>
> > <a href="#"><img src="images/photography/3.jpg" /></a>
> > <a href="#"><img src="images/photography/4.jpg" /></a>
> > <a href="#"><img src="images/photography/5.jpg" /></a>
> > </div>

>
> > <li><a href="#">Cloud 9</a></li>
> > <li><a href="#">The End</a></li>
> > </ul>
> > </div>
> > .....

>
> > Is this good code?

>
> > Thanks
> > Marco

>
> A URL would be more helpful. But the answer your question, run the
> page through the validator and see what it comes up with. Hint: a UL
> element can only contain LI elements.


Thanks!
I completely forgot about the W3C validator.
I did the validation test and, indeed, i got an error on the <ul>
element not having a <li> tag.
I've added a <li> tag that wraps around the <div> (weird as it may
sound) and validates correctly!

Thanks again dude!


code change:
> ...
> <!-- CONTENT_RIGHT -->
> <div id="content_right">
> <ul>
> <li><a href="#">Gallery One</a></li>
> <li><a href="#">Sky</a></li>
> <li><a href="#">Hello World</a></li>
> <li><a href="#">Tribute</a></li>
> <li>
> <div id="thumbnail">
> <a href="#"><img src="images/photography/1.jpg" /></a>
> <a href="#"><img src="images/photography/2.jpg" /></a>
> <a href="#"><img src="images/photography/3.jpg" /></a>
> <a href="#"><img src="images/photography/4.jpg" /></a>
> <a href="#"><img src="images/photography/5.jpg" /></a>
> </div>
> </li>
> <li><a href="#">Cloud 9</a></li>
> <li><a href="#">The End</a></li>
> </ul>
> </div>


 
Reply With Quote
 
Nik Coughlin
Guest
Posts: n/a
 
      11-08-2007
SM wrote:
>> <li><a href="#">Tribute</a></li>
>> <li>
>> <div id="thumbnail">
>> <a href="#"><img src="images/photography/1.jpg" /></a>
>> <a href="#"><img src="images/photography/2.jpg" /></a>
>> <a href="#"><img src="images/photography/3.jpg" /></a>
>> <a href="#"><img src="images/photography/4.jpg" /></a>
>> <a href="#"><img src="images/photography/5.jpg" /></a>
>> </div>
>> </li>
>> <li><a href="#">Cloud 9</a></li>


Do you need that div at all?

<li><a href="#">Tribute</a></li>
<li id="thumbnail">
<a href="#"><img src="images/photography/1.jpg" /></a>
<a href="#"><img src="images/photography/2.jpg" /></a>
<a href="#"><img src="images/photography/3.jpg" /></a>
<a href="#"><img src="images/photography/4.jpg" /></a>
<a href="#"><img src="images/photography/5.jpg" /></a>
</li>
<li><a href="#">Cloud 9</a></li>

And while you're at it you could be pedantic and say that the thumbnails are
a list as well:

<li><a href="#">Tribute</a></li>
<li>
<ul id="thumbnail">
<li><a href="#"><img src="images/photography/1.jpg" /></a></li>
<li><a href="#"><img src="images/photography/2.jpg" /></a></li>
<li><a href="#"><img src="images/photography/3.jpg" /></a></li>
<li><a href="#"><img src="images/photography/4.jpg" /></a></li>
<li><a href="#"><img src="images/photography/5.jpg" /></a></li>
</ul>
</li>
<li><a href="#">Cloud 9</a></li>


 
Reply With Quote
 
dorayme
Guest
Posts: n/a
 
      11-08-2007
In article
<. com>,
SM <> wrote:

> This is a sample of the code. Notice the insertion of the gallery
> beneath the <li> selected by the user.
> ...
> <!-- CONTENT_RIGHT -->
> <div id="content_right">
> <ul>
> <li><a href="#">Gallery One</a></li>
> <li><a href="#">Sky</a></li>
> <li><a href="#">Hello World</a></li>
> <li><a href="#">Tribute</a></li>
> <div id="thumbnail">
> <a href="#"><img src="images/photography/1.jpg" /></a>
> <a href="#"><img src="images/photography/2.jpg" /></a>
> <a href="#"><img src="images/photography/3.jpg" /></a>
> <a href="#"><img src="images/photography/4.jpg" /></a>
> <a href="#"><img src="images/photography/5.jpg" /></a>
> </div>
>
> <li><a href="#">Cloud 9</a></li>
> <li><a href="#">The End</a></li>
> </ul>
> </div>
> .....
>
> Is this good code?
>



Not really, you can't do this. This is better and you can
probably improve further:

http://tinyurl.com/27yrkx

--
dorayme
 
Reply With Quote
 
dorayme
Guest
Posts: n/a
 
      11-09-2007
In article <47337daf$>,
"Nik Coughlin" <> wrote:

> <li><a href="#">Tribute</a></li>
> <li id="thumbnail">
> <a href="#"><img src="images/photography/1.jpg" /></a>
> <a href="#"><img src="images/photography/2.jpg" /></a>
> <a href="#"><img src="images/photography/3.jpg" /></a>
> <a href="#"><img src="images/photography/4.jpg" /></a>
> <a href="#"><img src="images/photography/5.jpg" /></a>
> </li>
> <li><a href="#">Cloud 9</a></li>
>


This is not really correct because the idea is that the
thumbnails are an expansion of the item Tribute. Your
alternative, below, is correct but it is not pedantic.



> And while you're at it you could be pedantic and say that the thumbnails are
> a list as well:
>
> <li><a href="#">Tribute</a></li>
> <li>
> <ul id="thumbnail">
> <li><a href="#"><img src="images/photography/1.jpg" /></a></li>
> <li><a href="#"><img src="images/photography/2.jpg" /></a></li>
> <li><a href="#"><img src="images/photography/3.jpg" /></a></li>
> <li><a href="#"><img src="images/photography/4.jpg" /></a></li>
> <li><a href="#"><img src="images/photography/5.jpg" /></a></li>
> </ul>
> </li>
> <li><a href="#">Cloud 9</a></li>


--
dorayme
 
Reply With Quote
 
Adrienne Boswell
Guest
Posts: n/a
 
      11-09-2007
Gazing into my crystal ball I observed SM <>
writing in news: ups.com:

>
> Thanks again dude!
>
>


That would be Dudette!

--
Adrienne Boswell at Home
Arbpen Web Site Design Services
http://www.cavalcade-of-coding.info
Please respond to the group so others can share

 
Reply With Quote
 
Els
Guest
Posts: n/a
 
      11-09-2007
dorayme wrote:

> In article <47337daf$>,
> "Nik Coughlin" <> wrote:
>

[snip]
> This is not really correct because the idea is that the
> thumbnails are an expansion of the item Tribute. Your
> alternative, below, is correct but it is not pedantic.


[snip example where the nested ul is inside the list element
*following* the Tribute list element]

I'll be pedantic then , and say it is not correct. If the
thumbnails are indeed an expansion of the item Tribute, the list would
look like this:

<li><a href="#">Tribute</a>
<ul id="thumbnail">
<li><a href="#"><img src="images/photography/1.jpg" /></a></li>
<li><a href="#"><img src="images/photography/2.jpg" /></a></li>
<li><a href="#"><img src="images/photography/3.jpg" /></a></li>
<li><a href="#"><img src="images/photography/4.jpg" /></a></li>
<li><a href="#"><img src="images/photography/5.jpg" /></a></li>
</ul>
</li>
<li><a href="#">Cloud 9</a></li>


--
Els http://locusmeus.com/
 
Reply With Quote
 
dorayme
Guest
Posts: n/a
 
      11-09-2007
In article <1qr3hbl0xduir$.>,
Els <> wrote:

> dorayme wrote:
>
> > In article <47337daf$>,
> > "Nik Coughlin" <> wrote:
> >

> [snip]
> > This is not really correct because the idea is that the
> > thumbnails are an expansion of the item Tribute. Your
> > alternative, below, is correct but it is not pedantic.

>
> [snip example where the nested ul is inside the list element
> *following* the Tribute list element]
>
> I'll be pedantic then , and say it is not correct. If the
> thumbnails are indeed an expansion of the item Tribute, the list would
> look like this:
>
> <li><a href="#">Tribute</a>
> <ul id="thumbnail">
> <li><a href="#"><img src="images/photography/1.jpg" /></a></li>
> <li><a href="#"><img src="images/photography/2.jpg" /></a></li>
> <li><a href="#"><img src="images/photography/3.jpg" /></a></li>
> <li><a href="#"><img src="images/photography/4.jpg" /></a></li>
> <li><a href="#"><img src="images/photography/5.jpg" /></a></li>
> </ul>
> </li>
> <li><a href="#">Cloud 9</a></li>


That will teach me to be so soft-hearted and trusting! I had just
posted at the time:

http://tinyurl.com/27yrkx

what I thought was a *more* correct plan than the OP

and assumed without looking closely that Nick was following this
general idea.

--
dorayme
 
Reply With Quote
 
SM
Guest
Posts: n/a
 
      11-12-2007
On Nov 9, 3:38 am, dorayme <doraymeRidT...@optusnet.com.au> wrote:
> In article <1qr3hbl0xduir$.dew6rcfkfsqr....@40tude.net>,
>
>
>
> Els <els.aNOS...@tiscali.nl> wrote:
> > dorayme wrote:

>
> > > In article <47337da...@clear.net.nz>,
> > > "Nik Coughlin" <nrkn....@gmail.com> wrote:

>
> > [snip]
> > > This is not really correct because the idea is that the
> > > thumbnails are an expansion of the item Tribute. Your
> > > alternative, below, is correct but it is not pedantic.

>
> > [snip example where the nested ul is inside the list element
> > *following* the Tribute list element]

>
> > I'll be pedantic then , and say it is not correct. If the
> > thumbnails are indeed an expansion of the item Tribute, the list would
> > look like this:

>
> > <li><a href="#">Tribute</a>
> > <ul id="thumbnail">
> > <li><a href="#"><img src="images/photography/1.jpg" /></a></li>
> > <li><a href="#"><img src="images/photography/2.jpg" /></a></li>
> > <li><a href="#"><img src="images/photography/3.jpg" /></a></li>
> > <li><a href="#"><img src="images/photography/4.jpg" /></a></li>
> > <li><a href="#"><img src="images/photography/5.jpg" /></a></li>
> > </ul>
> > </li>
> > <li><a href="#">Cloud 9</a></li>

>
> That will teach me to be so soft-hearted and trusting! I had just
> posted at the time:
>
> http://tinyurl.com/27yrkx
>
> what I thought was a *more* correct plan than the OP
>
> and assumed without looking closely that Nick was following this
> general idea.
>
> --
> dorayme


Thank girls and guys!
Everything makes sense now....


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Looking for a Good Sim to Practice on and a good book? Pat MCSA 2 03-29-2008 12:19 AM
good algorithms come with practice and reading good code/books? vlsidesign C Programming 26 01-02-2007 09:50 AM
Looking for best practice advice on data access for SMALL web sites - not enterprise Alan Silver ASP .Net 13 06-29-2006 08:14 AM
Remember when your piano teacher taught you, "Practice, practice,practice ...?" Wayne Wastier Windows 64bit 3 06-10-2005 08:29 PM
Best Practice advice and schema implementation mat XML 0 03-04-2004 12:25 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57