<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Web International Awards</title>
	<atom:link href="http://www.webia.info/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.webia.info</link>
	<description></description>
	<lastBuildDate>Wed, 01 Sep 2010 07:20:50 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Stationery design showcase (#2)</title>
		<link>http://www.webia.info/showcase/stationery-design-showcase-2/</link>
		<comments>http://www.webia.info/showcase/stationery-design-showcase-2/#comments</comments>
		<pubDate>Wed, 01 Sep 2010 07:20:50 +0000</pubDate>
		<dc:creator>Bogdan Pop</dc:creator>
				<category><![CDATA[showcase]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[gallery]]></category>
		<category><![CDATA[stationary]]></category>
		<category><![CDATA[stationery]]></category>

		<guid isPermaLink="false">http://www.webia.info/?p=1762</guid>
		<description><![CDATA[Last year we had the first post that rounded up some incredible stationeries. Today I'm going to present new interesting stationeries. Moreover, I am announcing the launch of a new WebRaptor website: Stationery Wall. Stationery Wall is, you guessed it, an online stationeries design showcase you can browse for inspiration. Although we're just launching it, [...]]]></description>
			<content:encoded><![CDATA[<p>Last year we had the first post that rounded up some incredible stationeries. Today I'm going to present new interesting stationeries. Moreover, I am announcing the launch of a new WebRaptor website: <a href="http://www.stationerywall.info">Stationery Wall</a>. Stationery Wall is, you guessed it, an online stationeries design showcase you can browse for inspiration. Although we're just launching it, Stationery Wall already contains more than 50 designs. Out of those, 5 are showcased just below. Go ahead and visit <a href="http://www.stationerywall.info">Stationery Wall</a> and you might win a month of free advertising if you join the September contest! Details over Stationery Wall.</p>
<h2>Stationery showcase</h2>
<p class="imgpreview"><a><img src="http://www.stationerywall.info/wp-content/uploads/2010/08/949241248215515-550x367.jpg" alt="stationery design" /></a></p>
<a href="http://www.stationerywall.info/showcase/h2r-stationery-design/">H2R stationery design</a>

<p class="imgpreview"><a><img src="http://www.stationerywall.info/wp-content/uploads/2010/08/894271239851516-550x366.jpg" alt="stationery design" /></a></p>
<a href="http://www.stationerywall.info/showcase/ecocentric-stationery-design/">Ecocentric stationery design</a>

<p class="imgpreview"><a><img src="http://www.stationerywall.info/wp-content/uploads/2010/08/design-pretty-green-2-400x400.jpg" alt="stationery design" /></a></p>
<a href="http://www.stationerywall.info/showcase/pretty-green-stationery-design/">Pretty Green stationery design</a>

<p class="imgpreview"><a><img src="http://www.stationerywall.info/wp-content/uploads/2010/08/221223_3VjkNHHZbs9WV9eFhZTf5sZfS-550x370.jpg" alt="stationery design" /></a></p>
<a href="http://www.stationerywall.info/showcase/nest-stationery-design/">Nest stationery design</a>

<p class="imgpreview"><a><img src="http://www.stationerywall.info/wp-content/uploads/2010/08/185157_XOuuKwqfRZJIb8hFltwC0BqHj-533x400.jpg" alt="stationery design" /></a></p>
<a href="http://www.stationerywall.info/showcase/talent-stationery-design/">Talent stationery design</a>]]></content:encoded>
			<wfw:commentRss>http://www.webia.info/showcase/stationery-design-showcase-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building a live news blogging system in JSP [II]</title>
		<link>http://www.webia.info/articles/tutorials/building-a-live-news-blogging-system-in-jsp-ii/</link>
		<comments>http://www.webia.info/articles/tutorials/building-a-live-news-blogging-system-in-jsp-ii/#comments</comments>
		<pubDate>Wed, 25 Aug 2010 10:00:21 +0000</pubDate>
		<dc:creator>Bogdan Pop</dc:creator>
				<category><![CDATA[tutorials]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[jsp]]></category>
		<category><![CDATA[live news system]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.webia.info/?p=1747</guid>
		<description><![CDATA[

Last week I started building a live news blogging system using JSP. This is a follow up tutorial I've decided to do after seeing the success of the previous series, which described how to build the same web application using php as backend.

Adding news to the database

In today's part I am going to code the [...]]]></description>
			<content:encoded><![CDATA[<p class="imgpreview"><a href="http://www.webia.info/wp-content/uploads/2010/03/lns_preview_full.jpg" title="Tutorial app preview"><img src="http://www.webia.info/wp-content/uploads/2010/03/lnw_preview.jpg" alt="Tutorial app preview" /></a></p>
<p>
Last week I started <a href="http://www.webia.info/articles/tutorials/building-a-live-news-blogging-system-in-jsp/">building a live news blogging system using JSP</a>. This is a follow up tutorial I've decided to do after seeing the success of the previous series, which described how to build the same web application using php as backend.
</p>
<h2>Adding news to the database</h2>
<p>
In today's part I am going to code the JSP files needed to add content to the database. The same functionality has already been developed using PHP in the third part of the original tutorial series located over <a href="http://www.webia.info/articles/tutorials/building-a-live-news-blogging-system-in-php-spiced-with-html5-css3-and-jquery-part-iii/">here</a>. The PHP version contained a function that was used to generate a select field into the add news form which would contain all available news categories. Differently, I've chosen not to include such a feature in a JSP function. Instead, I've added it directly into the HTML template. Not so fancy, but it works.
</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;form action=&quot;addnews.jsp&quot; method=&quot;post&quot; accept-charset=&quot;utf-8&quot; id=&quot;form-overlay&quot;&gt;
	&lt;fieldset&gt;
		&lt;label for=&quot;title&quot;&gt;Title : &lt;/label&gt;
		&lt;input type=&quot;text&quot; name=&quot;title&quot; value=&quot;&quot; id=&quot;title&quot; class=&quot;all-rounded&quot;/&gt;
		&lt;label for=&quot;formcategory&quot;&gt;Category :&lt;/label&gt;
		&lt;select name=&quot;formcategory&quot; id=&quot;formcategory&quot; length=&quot;1&quot;&gt;
			&lt;% 						
			st = new StringTokenizer(categories,&quot;-&quot;);
			query = &quot;SELECT name FROM Categories WHERE id&gt;0 ORDER BY name ASC&quot;;
			rs = statement.executeQuery(query);
			count = 0;
				while (rs.next()) 
				{
					count++;
					String name = rs.getString(&quot;name&quot;);
					if(count==1) { %&gt; &lt;option selected=&quot;selected&quot; value=&quot;&lt;%=name%&gt;&quot;&gt;&lt;%=name%&gt;&lt;/option&gt; &lt;% }
					else { %&gt; &lt;option value=&quot;&lt;%=name%&gt;&quot;&gt;&lt;%=name%&gt;&lt;/option&gt; &lt;% }
				}
			if(count==0) { %&gt; &lt;option value=&quot;none&quot;&gt;none&lt;/option&gt; &lt;% }
			%&gt;
		&lt;/select&gt;
		&lt;label for=&quot;body&quot;&gt;Body text :&lt;/label&gt;
		&lt;textarea name=&quot;body&quot; rows=&quot;8&quot; cols=&quot;40&quot; class=&quot;all-rounded&quot;&gt;&lt;/textarea&gt;
		&lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Add news&quot; id=&quot;submit&quot; class=&quot;submit all-rounded&quot; /&gt;
	&lt;/fieldset&gt;
&lt;/form&gt;</pre></td></tr></table></div>



<p>
As you've seen in the <a href="http://www.webia.info/articles/tutorials/building-a-live-news-blogging-system-in-jsp/">previous part</a>, the code on lines 8 to 10 is used to create a SQL query and run it. Lines 11/19 check if the SQL query returned an empty result. If yes, a default news category is created as the unique option; current case: <em>none</em>. If there's at least one category in the database, the code between line 12 and 17 gets the names of each category and adds each of them to the select field. The first category that's found is also pre-selected.
</p>
<h2>Processing the add news form</h2>
<p>
The form used to insert news in the database needs to be processed. The script is pretty straightforward, especially because I've already shown basic SQL queries in JSP just above ( or in the previous article in the series ). The first line of the script that processes the form is the usual line that imports all required libraries. All the following lines up to line 18 are used to create and instantiate the resources required to perform different operations on the mySQL database. Here's the full code:
</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
</pre></td><td class="code"><pre class="jsp" style="font-family:monospace;">&lt;%@ page import=&quot;java.sql.*&quot; import=&quot;java.util.*&quot; session=&quot;true&quot; import=&quot;Javax.servlet.http.*&quot; import=&quot;java.security.*&quot; %&gt;
&nbsp;
&lt;%
&nbsp;
	String database = &quot;lab8&quot;;
	String user = &quot;root&quot;;
	String pass = &quot;thebeastlocal&quot;;
	String table = &quot;News&quot;;
&nbsp;
	String connectionURL = &quot;jdbc:mysql://localhost:3306/&quot;+database+&quot;?user=&quot;+user+&quot;;password=&quot;+pass;
	Connection connection = null;
	Statement statement = null;
	Statement update = null;
	ResultSet rs = null;
&nbsp;
	Class.forName(&quot;com.mysql.jdbc.Driver&quot;).newInstance();
	connection = DriverManager.getConnection(connectionURL,user,pass);
	statement = connection.createStatement();
&nbsp;
	if(session.getAttribute(&quot;loggedin&quot;)!=null)
	{
		String title = &quot;&quot;;
		String formcategory = &quot;&quot;;
		String body = &quot;&quot;;
		int error = 0;
&nbsp;
		if(request.getParameter(&quot;title&quot;)!=null) title = request.getParameter(&quot;title&quot;);
		else error = 1;
		if(request.getParameter(&quot;formcategory&quot;)!=null) formcategory = request.getParameter(&quot;formcategory&quot;);
		else error = 1;
		if(request.getParameter(&quot;body&quot;)!=null) body = request.getParameter(&quot;body&quot;);
		else error = 1;
&nbsp;
		if(error==1)
		{
			response.sendRedirect(&quot;index.jsp?error=Please input information in all fields&quot;);
		}
		else
		{
			String username = (String) session.getAttribute(&quot;username&quot;);
			try
			{
				String query = &quot;INSERT // INTO News(title,body,owner,publishing_date,publishing_time,category) VALUES('&quot;+title+&quot;','&quot;+body+&quot;','&quot;+username+&quot;',NOW(),NOW(),'&quot;+formcategory+&quot;')&quot;;
				// remove // between INSERT and INTO in above line
				statement.executeUpdate(query);				
			}
			catch (Exception e)
			{
				%&gt;&lt;%=e%&gt;&lt;%
			}
			response.sendRedirect(&quot;index.jsp?msg=News added to the system.&quot;);
		}
	}
	else response.sendRedirect(&quot;index.jsp?error=You must be logged in to access this feature.&quot;);
%&gt;</pre></td></tr></table></div>



<p>
Lines 20 and 54 in the above code check if the user trying to add a news to the database is logged in, as only logged in users are allowed to add items to the database. Lines 22 to 32 are used to initialize the variables which retain information users have inserted into the form fields on the previous page. On lines 34/36 errors are checked, and if any errors are found the users are redirected to the homepage of the web app and error messages are displayed. The code on line 40 gets the username of the person trying to add a news to the database as each news has an author and we need to know the info before inserting new items in the database. The <em>try catch</em> block between lines 41 and 50 is used to add the news to the database, or if any exceptions occur, catch and display them. If everything goes as planned the code on line 51 redirects users to the homepage and triggers a success message.
</p>
<p>That's all it takes to nicely add information to a database using Java Server Pages. If you enjoyed the article, you can stay updated to new content via our <a href="http://feeds2.feedburner.com/WebInternationalAwards" target="_new">RSS feed</a> or by <a href="http://feedburner.google.com/fb/a/mailverify?uri=WebInternationalAwards&#038;loc=en_US" target="_new">email</a>.
</p>]]></content:encoded>
			<wfw:commentRss>http://www.webia.info/articles/tutorials/building-a-live-news-blogging-system-in-jsp-ii/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building a live news blogging system in JSP</title>
		<link>http://www.webia.info/articles/tutorials/building-a-live-news-blogging-system-in-jsp/</link>
		<comments>http://www.webia.info/articles/tutorials/building-a-live-news-blogging-system-in-jsp/#comments</comments>
		<pubDate>Wed, 18 Aug 2010 04:24:20 +0000</pubDate>
		<dc:creator>Bogdan Pop</dc:creator>
				<category><![CDATA[tutorials]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[jsp]]></category>
		<category><![CDATA[live news system]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.webia.info/?p=1736</guid>
		<description><![CDATA[

About 5 months ago I started a series of tutorials which described the process of building a live news blogging system in php. When the series ended, I promised that another series will follow and will describe the process of building the same web app using JSP. This article is the first of its series, [...]]]></description>
			<content:encoded><![CDATA[<p class="imgpreview"><a href="http://www.webia.info/wp-content/uploads/2010/03/lns_preview_full.jpg" title="Tutorial app preview"><img src="http://www.webia.info/wp-content/uploads/2010/03/lnw_preview.jpg" alt="Tutorial app preview" /></a></p>
<p>
About 5 months ago I started a series of tutorials which described the process of <a href="http://www.webia.info/articles/tutorials/building-a-live-news-blogging-system-in-php-spiced-with-html5-css3-and-jquery-part-i/">building a live news blogging system in php</a>. When the series ended, I promised that another series will follow and will describe the process of building the same web app using JSP. This article is the first of its series, and contains the introductory part of what's needed in this tutorial series, as well as some basic JSP code.
</p>
<p>First of all, please read the first part of the original series <a href="http://www.webia.info/articles/tutorials/building-a-live-news-blogging-system-in-php-spiced-with-html5-css3-and-jquery-part-i/">here</a> as it describes and shows the source codes for the user interface of the web application, namely HTML5, CSS and some jQuery.</p>
<p>You should also check out the second part of the original tutorial <a href="http://www.webia.info/articles/tutorials/building-a-live-news-blogging-system-in-php-spiced-with-html5-css3-and-jquery-part-ii/">here</a>, as this part contains the database model and some more jQuery. There's also some bits of PHP, but those aren't mandatory for today's article.</p>
<h2>login.jsp page</h2>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
58
59
60
61
62
63
64
65
66
</pre></td><td class="code"><pre class="jsp" style="font-family:monospace;">&lt;%@ page import=&quot;java.sql.*&quot; import=&quot;java.util.*&quot; session=&quot;true&quot; import=&quot;Javax.servlet.http.*&quot; import=&quot;java.security.*&quot; %&gt;
&nbsp;
&lt;%
&nbsp;
	String database = &quot;lab8&quot;;
	String user = &quot;user here&quot;;
	String pass = &quot;pass here&quot;;
	String table = &quot;Users&quot;;
&nbsp;
	String connectionURL = &quot;jdbc:mysql://localhost:3306/&quot;+database+&quot;?user=&quot;+user+&quot;;password=&quot;+pass;
	Connection connection = null;
	Statement statement = null;
	Statement update = null;
	ResultSet rs = null;
&nbsp;
	Class.forName(&quot;com.mysql.jdbc.Driver&quot;).newInstance();
	connection = DriverManager.getConnection(connectionURL,user,pass);
	statement = connection.createStatement();
&nbsp;
	String username = &quot;&quot;;
	String password = &quot;&quot;;
	int error = 0;
	if(request.getParameter(&quot;username&quot;)!=null) username = request.getParameter(&quot;username&quot;);
	else error = 1;
	if(request.getParameter(&quot;password&quot;)!=null) password = request.getParameter(&quot;password&quot;);
	else error = 1;
	if(error==1)
	{
		response.sendRedirect(&quot;index.jsp?error=Please input username and password&quot;);
	}
	else
	{
			MessageDigest mdAlgorithm = MessageDigest.getInstance(&quot;MD5&quot;);
			mdAlgorithm.update(password.getBytes());
&nbsp;
			byte[] digest = mdAlgorithm.digest();
			StringBuffer hexString = new StringBuffer();
&nbsp;
			for (int i = 0; i &lt; digest.length; i++) 
			{
			    password = Integer.toHexString(0xFF &amp; digest[i]);
&nbsp;
			    if (password.length() &lt; 2) 
				{
			        password = &quot;0&quot; + password;
			    }
&nbsp;
			    hexString.append(password);
			}
&nbsp;
			password = hexString.toString();
			String query = &quot;SELECT * FROM Users WHERE username='&quot;+username+&quot;' AND password='&quot;+password+&quot;'&quot;;
			rs = statement.executeQuery(query);
			if(rs.next())
			{
				session.setAttribute(&quot;loggedin&quot;,&quot;1&quot;);
				session.setAttribute(&quot;username&quot;,username);
&nbsp;
				response.sendRedirect(&quot;index.jsp?msg=Logged in succesfully.&quot;);
			}
			else 
			{
				response.sendRedirect(&quot;index.jsp?error=Invalid login data.&quot;);
			}
	}
%&gt;</pre></td></tr></table></div>



<p>The first line of the code above contains instructions to include different libraries that will be used throughout the entire jsp file. The following four lines of code are in fact the variables that will be used to store database connection settings. In the next set of lines we create the datatypes that we will use to create an sql connection, perform sql queries and handle the results returned by the queries. On lines 16 to 18 we instantiate the mysql driver and connect to the database.</p>
<p>The instructions between lines 20 and 30 test if the visitor has inputed his username and password information in the form that send him to the login page. If the user's hasn't filled in required information, the request is denied. Lines 33 to 50 are used to encrypt the password the user typed in the login form. Passwords in the database are encrypted to ensure that, even if third parties gain access to the database, the passwords aren't exposed.</p>
<p>
The following two lines make an SQL query to check if the user credentials are valid. If they are, lines 56 to 59 are used to create required login sessions and redirect the user to the homepage, while the code on line 63 redirects the user to the homepage after an invalid login.
</p>
<h2>logout.jsp</h2>
<p>The logout process is much more simple, and the following code snippet does the trick. This snippet also contains the imports found in the login.jsp file, one line of code that destroys the session and one that redirects the user to the homepage.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="jsp" style="font-family:monospace;">&lt;%@ page import=&quot;java.sql.*&quot; import=&quot;java.util.*&quot; session=&quot;true&quot; import=&quot;Javax.servlet.http.*&quot; import=&quot;java.security.*&quot; %&gt;
&nbsp;
&lt;%
	session.removeAttribute(&quot;loggedin&quot;);
	response.sendRedirect(&quot;index.jsp?msg=Successfully logged out&quot;);
%&gt;</pre></td></tr></table></div>



<p>
While the php application also contained a functions.php file, this does not. Having that said, this is the end of the first part of the tutorial. You can stay updated to new content via our <a href="http://feeds2.feedburner.com/WebInternationalAwards" target="_new">RSS feed</a> or by <a href="http://feedburner.google.com/fb/a/mailverify?uri=WebInternationalAwards&#038;loc=en_US" target="_new">email</a>.
</p>]]></content:encoded>
			<wfw:commentRss>http://www.webia.info/articles/tutorials/building-a-live-news-blogging-system-in-jsp/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Build a POI map using jQuery &amp; Google Maps v3</title>
		<link>http://www.webia.info/articles/jquery-articles/build-a-poi-map-using-jquery-google-maps-v3/</link>
		<comments>http://www.webia.info/articles/jquery-articles/build-a-poi-map-using-jquery-google-maps-v3/#comments</comments>
		<pubDate>Wed, 11 Aug 2010 15:26:51 +0000</pubDate>
		<dc:creator>Bogdan Pop</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[geolocation]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[location]]></category>
		<category><![CDATA[map]]></category>
		<category><![CDATA[poi]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.webia.info/?p=1706</guid>
		<description><![CDATA[
This is the incipient work from a bigger project that I worked on which uses Google Maps. I decided to share it with you as it can be used in a variety of ways and places. You can use it to locate around a map your company's offices, stores, museums or any other interest points [...]]]></description>
			<content:encoded><![CDATA[<p>
This is the incipient work from a bigger project that I worked on which uses Google Maps. I decided to share it with you as it can be used in a variety of ways and places. You can use it to locate around a map your company's offices, stores, museums or any other interest points you need to present to your website's visitors.
</p>
<p>
The tutorial is fairly simple as it doesn't include advanced programming or CSS rules. Having that said, here's a screenshot of the final product.
</p>

<p class="imgpreview"><a href="http://www.webia.info/wp-content/uploads/2010/08/office_location.png" title="Tutorial preview"><img src="http://www.webia.info/wp-content/uploads/2010/08/office_location_small.jpg" alt="Tutorial preview" /></a></p>

<p>
As you can see the application, if I can call it that way, has a sidebar that contains a list of POIs (Point of Interest), a diagnosis header that displays information about what's going on and a map. Let's code the HTML structure:
</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;div id=&quot;home-wrapper&quot;&gt;
	&lt;div id=&quot;logo&quot;&gt;
		&lt;a href=&quot;http://www.webraptor.eu&quot; target=&quot;_self&quot;&gt;&lt;img src=&quot;logo.jpg&quot; width=&quot;245&quot; height=&quot;40&quot; alt=&quot;WebRaptor&quot; /&gt;&lt;/a&gt;
	&lt;/div&gt;
	&lt;div id=&quot;home-messages&quot;&gt;
		Trying to determine your location...Please allow browser to share location if prompted
	&lt;/div&gt;
	&lt;span class=&quot;clear&quot;&gt;&amp;nbsp;&lt;/span&gt;
	&lt;div id=&quot;home-sidebar&quot;&gt;
		&lt;h1&gt;Our offices locations&lt;/h1&gt;
		&lt;ul&gt;
			&lt;li&gt;&lt;a href=&quot;#&quot; rel=&quot;40.453577,-3.68763, 
			&lt;strong&gt;Venue: &lt;/strong&gt;Estadio Santiago Bernabeu&lt;br /&gt;
			&lt;strong&gt;Address: &lt;/strong&gt;Avenida de Concha Espina; No 1; 28036; Madrid&lt;br /&gt;
			&lt;strong&gt;Phone: &lt;/strong&gt;+34 (91) 398 4300&lt;br /&gt;
			&lt;strong&gt;Fax: &lt;/strong&gt;+34 (91) 344 0695&lt;br /&gt;
			&lt;strong&gt;Email: &lt;/strong&gt;&lt;a href='mailto:realmadrid@club.realmadrid.com'&gt;realmadrid@club.realmadrid.com&lt;/a&gt;&lt;br /&gt;
			&quot; target=&quot;_self&quot;&gt;Estadio Santiago Bernabeu&lt;/a&gt;&lt;/li&gt;
			&lt;li&gt;&lt;a href=&quot;#&quot; rel=&quot;41.934115,12.45575, 
			&lt;strong&gt;Venue: &lt;/strong&gt;Stadio Olimpico&lt;br /&gt;
			&lt;strong&gt;Address: &lt;/strong&gt;&lt;br /&gt;
			&lt;strong&gt;Phone: &lt;/strong&gt;&lt;br /&gt;
			&lt;strong&gt;Fax: &lt;/strong&gt;&lt;br /&gt;
			&lt;strong&gt;Email: &lt;/strong&gt;&lt;a href='mailto:'&gt;&lt;/a&gt;&lt;br /&gt;
			&quot; target=&quot;_self&quot;&gt;Stadio Olimpico - Rome&lt;/a&gt;&lt;/li&gt;
		&lt;/ul&gt;
	&lt;/div&gt;
&nbsp;
	&lt;div id=&quot;map-wrapper&quot;&gt;
		&lt;div id=&quot;map&quot;&gt;
&nbsp;
		&lt;/div&gt;	
	&lt;/div&gt;
&lt;/div&gt;</pre></td></tr></table></div>




<p>
The role of the <em>home-wrapper</em> div is to hold the contents of the page centered in the browser window. The <em>home-messages</em> div is the one that holds the diagnosis messages in place, the <em>home-sidebar</em> div holds the POIs list while <em>map-wrapper</em> and <em>map</em> serve as a map placeholder.
</p>
<p>
As you can see, the <em>li</em> items inside the unordered list located in the sidebar contain all information that's provided for each point of interest. No external files or database queries are used. The information is contained within a <em>rel</em> attribute of the anchor tag that's inserted in each <em>li</em> item.
</p>
<p>
The above HTML code is to be placed inside the body of the page, while the following into the header, as it contains links to CSS files and javascript pointers.
</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;link rel=&quot;stylesheet&quot; href=&quot;css.css&quot; type=&quot;text/css&quot; media=&quot;screen&quot; title=&quot;no title&quot; charset=&quot;utf-8&quot; /&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://www.google.com/jsapi?key={APIKEY}&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
	google.load(&quot;jquery&quot;, &quot;1.4.2&quot;);	  
&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://maps.google.com/maps/api/js?sensor=true&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;js/OfficeLocation.js&quot; type=&quot;text/javascript&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;</pre></td></tr></table></div>



<p>
The CSS file isn't complicated at all.
</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #00AA00;">*</span>		<span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">outline</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span><span style="color: #993333;">inherit</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #993333;">inherit</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
body		<span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">font-family</span><span style="color: #3333ff;">:Geneva</span><span style="color: #00AA00;">,</span> “Lucida Sans”<span style="color: #00AA00;">,</span> “Lucida Grande”<span style="color: #00AA00;">,</span> “Lucida Sans Unicode”<span style="color: #00AA00;">,</span> Verdana<span style="color: #00AA00;">,</span> <span style="color: #993333;">sans-serif</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;"><span style="color: #cc66cc;">62.5</span>%</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.clear</span> 	<span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">clear</span><span style="color: #00AA00;">:</span><span style="color: #993333;">both</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#logo</span>	<span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">245px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">40px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span><span style="color: #933;">40px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span><span style="color: #993333;">center</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#home-wrapper</span>	<span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">930px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #933;">0px</span> <span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">25px</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">12px</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#home-messages</span>	<span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">645px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">40px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span><span style="color: #933;">40px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">25px</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#FFFFCC</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#EEEEBB</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#home-sidebar</span>		<span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">243px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">400px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">20px</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #933;">10px</span> <span style="color: #933;">25px</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#FFFFCC</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#EEEEBB</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#map-wrapper</span>		<span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">645px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">400px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">10px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#FFFFCC</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#EEEEBB</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#map</span>			<span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">645px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">400px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">0px</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>	
<span style="color: #cc00cc;">#infowin-overlay</span>	<span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">400px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">80px</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#infowin-overlay</span> strong	<span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">clear</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span><span style="color: #993333;">bold</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">100px</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
&nbsp;
h1	<span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">15px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">10px</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span><span style="color: #993333;">center</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#EEEEBB</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#339933</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
ul 	<span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">list-style</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
li a	<span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">5px</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#999</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>



<p>
What's new in the CSS file is the <em>infowin-overlay</em> identifier used, which is nowhere to be found in our HTML file. That's due to the fact that it is the identifier of the overlay window that is displayed once a visitor clicks a POIs marker on the map. The overlay is added to the DOM by the javascript code that follows, which contains all that's required for the tutorial to be complete and working at warp speed.
</p>

<p class="imgpreview"><a href="http://www.webia.info/wp-content/uploads/2010/08/office_location_overlay.jpg" title="Map overlay preview"><img src="http://www.webia.info/wp-content/uploads/2010/08/office_location_overlay.jpg" alt="Map overlay preview" /></a></p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> map<span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// global var to store the google map</span>
<span style="color: #003366; font-weight: bold;">var</span> centerCoord <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">LatLng</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">46.782101</span><span style="color: #339933;">,</span><span style="color: #CC0000;">23.643855</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// tulghesului street, Cluj-Napoca</span>
<span style="color: #003366; font-weight: bold;">var</span> centerCoord <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">LatLng</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">40.453577</span><span style="color: #339933;">,-</span><span style="color: #CC0000;">3.68763</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// Estadio Santiago Bernabeu, Madrid</span>
<span style="color: #003366; font-weight: bold;">var</span> browserDetectedLocation <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// global variables used throughout the js functionality</span>
<span style="color: #003366; font-weight: bold;">var</span> markersArray <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> infoWindow <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">InfoWindow</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> setLocation<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #006600; font-style: italic;">// try to get user location via W3C standard Geolocation in browsers or via Google Gears</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>navigator.<span style="color: #660066;">geolocation</span><span style="color: #009900;">&#41;</span> 
	<span style="color: #009900;">&#123;</span>
	    navigator.<span style="color: #660066;">geolocation</span>.<span style="color: #660066;">getCurrentPosition</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>position<span style="color: #009900;">&#41;</span> 
		<span style="color: #009900;">&#123;</span>
			blueIcon <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;http://www.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png&quot;</span><span style="color: #339933;">;</span>
			browserDetectedLocation <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">LatLng</span><span style="color: #009900;">&#40;</span>position.<span style="color: #660066;">coords</span>.<span style="color: #660066;">latitude</span><span style="color: #339933;">,</span>position.<span style="color: #660066;">coords</span>.<span style="color: #660066;">longitude</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			map.<span style="color: #660066;">setCenter</span><span style="color: #009900;">&#40;</span>browserDetectedLocation<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #003366; font-weight: bold;">var</span> marker <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">Marker</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
			      position<span style="color: #339933;">:</span> browserDetectedLocation<span style="color: #339933;">,</span> 
			      map<span style="color: #339933;">:</span> map<span style="color: #339933;">,</span> 
			      title<span style="color: #339933;">:</span> <span style="color: #3366CC;">'You are here'</span><span style="color: #339933;">,</span>
			 	  icon<span style="color: #339933;">:</span> blueIcon
			<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#home-messages'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Location detected. Please wait...&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	     <span style="color: #006600; font-style: italic;">// error getting location, though supported</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#home-messages'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Your location cannot be detected.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>google.<span style="color: #660066;">gears</span><span style="color: #009900;">&#41;</span> 
	<span style="color: #006600; font-style: italic;">// if location not found using W3C standard try with Google Gears if browser supports it</span>
	<span style="color: #009900;">&#123;</span>
	    <span style="color: #003366; font-weight: bold;">var</span> geo <span style="color: #339933;">=</span> google.<span style="color: #660066;">gears</span>.<span style="color: #660066;">factory</span>.<span style="color: #660066;">create</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'beta.geolocation'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	    geo.<span style="color: #660066;">getCurrentPosition</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>position<span style="color: #009900;">&#41;</span> 
		<span style="color: #009900;">&#123;</span>
			blueIcon <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;http://www.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png&quot;</span><span style="color: #339933;">;</span>
			browserDetectedLocation <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">LatLng</span><span style="color: #009900;">&#40;</span>position.<span style="color: #660066;">latitude</span><span style="color: #339933;">,</span>position.<span style="color: #660066;">longitude</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			map.<span style="color: #660066;">setCenter</span><span style="color: #009900;">&#40;</span>browserDetectedLocation<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #003366; font-weight: bold;">var</span> marker <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">Marker</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
			      position<span style="color: #339933;">:</span> browserDetectedLocation<span style="color: #339933;">,</span> 
			      map<span style="color: #339933;">:</span> map<span style="color: #339933;">,</span> 
			      title<span style="color: #339933;">:</span> <span style="color: #3366CC;">'You are here'</span><span style="color: #339933;">,</span>
				  icon<span style="color: #339933;">:</span> blueIcon
			<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#home-messages'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Location detected. Please wait...&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #006600; font-style: italic;">// error getting location, though supported</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#home-messages'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Your location cannot be found.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> 
	<span style="color: #000066; font-weight: bold;">else</span>	
	<span style="color: #009900;">&#123;</span>
		<span style="color: #006600; font-style: italic;">// Browser doesn't support Geolocation</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#home-messages'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Your location cannot be found.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>	
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> InitMap<span style="color: #009900;">&#40;</span>options<span style="color: #339933;">,</span> mapIdentifier<span style="color: #339933;">,</span> defaultLocation<span style="color: #339933;">,</span> detectLocation<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// function to initialize map</span>
	<span style="color: #003366; font-weight: bold;">var</span> settings <span style="color: #339933;">=</span> <span style="color: #006600; font-style: italic;">// json variable for default settings</span>
	<span style="color: #009900;">&#123;</span>
		zoom<span style="color: #339933;">:</span> <span style="color: #CC0000;">15</span><span style="color: #339933;">,</span>
		center<span style="color: #339933;">:</span> defaultLocation<span style="color: #339933;">,</span>
		mapTypeId<span style="color: #339933;">:</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">MapTypeId</span>.<span style="color: #660066;">SATELLITE</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>options<span style="color: #339933;">!=</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> settings <span style="color: #339933;">=</span> options<span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// if no options provided, start the map with default settings</span>
	map <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">Map</span><span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>mapIdentifier<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> settings<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	map.<span style="color: #660066;">setCenter</span><span style="color: #009900;">&#40;</span>defaultLocation<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>detectLocation<span style="color: #339933;">==</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span> setLocation<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// try to get user location via W3C standard Geolocation in browsers or via Google Gears</span>
	<span style="color: #000066; font-weight: bold;">else</span>
	<span style="color: #009900;">&#123;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#home-messages'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Click an office on the left to view its location.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">return</span> map<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> handle_clicks<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#home-sidebar ul li a'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">live</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		clearOverlays<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> coordString <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'rel'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> coordTitle <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> coordArray <span style="color: #339933;">=</span> coordString.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">','</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> update2Location <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">LatLng</span><span style="color: #009900;">&#40;</span>coordArray<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>coordArray<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		map.<span style="color: #660066;">setCenter</span><span style="color: #009900;">&#40;</span>update2Location<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		addMarker<span style="color: #009900;">&#40;</span>update2Location<span style="color: #339933;">,</span>coordTitle<span style="color: #339933;">,</span>coordArray<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#home-messages'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Viewing: &quot;</span><span style="color: #339933;">+</span>coordTitle<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> addMarker<span style="color: #009900;">&#40;</span>m_position<span style="color: #339933;">,</span>m_title<span style="color: #339933;">,</span>m_infowindow<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	marker <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">Marker</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
	  	position<span style="color: #339933;">:</span> m_position<span style="color: #339933;">,</span>
	  	map<span style="color: #339933;">:</span> map<span style="color: #339933;">,</span>
		title<span style="color: #339933;">:</span> m_title
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	markersArray.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>marker<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  	<span style="color: #003366; font-weight: bold;">var</span> mark <span style="color: #339933;">=</span> markersArray.<span style="color: #660066;">pop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">event</span>.<span style="color: #660066;">addListener</span><span style="color: #009900;">&#40;</span>mark<span style="color: #339933;">,</span> <span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		infoWindow.<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span>map<span style="color: #339933;">,</span>mark<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> stringContent <span style="color: #339933;">=</span> m_infowindow<span style="color: #339933;">;</span>
		infoWindow.<span style="color: #660066;">setContent</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&lt;div id=<span style="color: #000099; font-weight: bold;">\&quot;</span>infowin-overlay<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">+</span>stringContent<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&lt;/div&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		overlayHeight <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#infowin-overlay'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">height</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		overlayWidth <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#infowin-overlay'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">width</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#infowin-overlay'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'height'</span><span style="color: #339933;">,</span>overlayHeight<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#infowin-overlay'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'width'</span><span style="color: #339933;">,</span>overlayWidth<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	markersArray.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>mark<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> clearOverlays<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>markersArray<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #000066; font-weight: bold;">in</span> markersArray<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      markersArray<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">setMap</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009966; font-style: italic;">/* end of functions */</span>
&nbsp;
$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#map'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// only initialize the map if map is located inside the page</span>
		map <span style="color: #339933;">=</span> InitMap<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'map'</span><span style="color: #339933;">,</span> centerCoord<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// initialize the map on default location</span>
		handle_clicks<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// click events handling by jQuery	</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>



<p>
I've added comments to the most important lines of jQuery above. The <em>setLocation()</em> function tries to detect user location and center the map around his location. The <em>InitMap()</em> function is used to get the entire thing rolling, and takes a couple of arguments that allows you to set the default location displayed when the map loads, as well as to enable or disable user location tracking.
</p>
<p>
The <em>handle_clicks()</em> function is used to track clicks on the items contained in the sidebar list and move the map around on top of the clicked point of interest. <em>addMarker()</em> is used to add a marker to the map, marker which represents the location of a POI and which users can click to have a detailed overlay displayed. Finally, clear_overlays() clears existing overlays to avoid duplicated content.
</p>
<h2>Demo</h2>
<p>I've prepared a demo of the tutorial over <a href="http://demos.webia.info/map_demo/map.html">here</a>.</p>
<p>If you enjoyed this article you can stay updated to new content via our <a href="http://feeds2.feedburner.com/WebInternationalAwards" target="_new">RSS feed</a> or by <a href="http://feedburner.google.com/fb/a/mailverify?uri=WebInternationalAwards&#038;loc=en_US" target="_new">email</a>.</p>	]]></content:encoded>
			<wfw:commentRss>http://www.webia.info/articles/jquery-articles/build-a-poi-map-using-jquery-google-maps-v3/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Building a live news blogging system in php. Spiced with HTML5, CSS3 and jQuery [sources]</title>
		<link>http://www.webia.info/articles/tutorials/building-a-live-news-blogging-system-in-php-spiced-with-html5-css3-and-jquery-sources/</link>
		<comments>http://www.webia.info/articles/tutorials/building-a-live-news-blogging-system-in-php-spiced-with-html5-css3-and-jquery-sources/#comments</comments>
		<pubDate>Tue, 13 Jul 2010 08:00:47 +0000</pubDate>
		<dc:creator>Bogdan Pop</dc:creator>
				<category><![CDATA[tutorials]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[live news system]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.webia.info/?p=1701</guid>
		<description><![CDATA[

About a month ago the huge tutorial on building a live news blogging system was completed. Today I am releasing the source codes of the tutorial so that you can finally play with the web application however you like.

Demo

You can check out the demo part of the tutorial before you download the source code. Furthermore, [...]]]></description>
			<content:encoded><![CDATA[<p class="imgpreview"><a href="http://www.webia.info/wp-content/uploads/2010/03/lns_preview_full.jpg" title="Tutorial app preview"><img src="http://www.webia.info/wp-content/uploads/2010/03/lnw_preview.jpg" alt="Tutorial app preview" /></a></p>
<p>
About a month ago the huge tutorial on building a live news blogging system was completed. Today I am releasing the source codes of the tutorial so that you can finally play with the web application however you like.
</p>
<h2>Demo</h2>
<p>
You can check out the <a href="http://www.webia.info/articles/tutorials/building-a-live-news-blogging-system-in-php-spiced-with-html5-css3-and-jquery-demo/">demo part of the tutorial</a> before you download the source code. Furthermore, a demo of the application is available <a href="http://demos.webia.info/news_system">over here</a>.
</p>
<h2>Source code</h2>
<p>
The full source code of the tutorial is available for download <a href="http://demos.webia.info/news_system/LiveNewsSystem.zip">over here</a>.
</p>
<p>
If you liked this tutorial series, stay updated to new content via our <a href="http://feeds2.feedburner.com/WebInternationalAwards" target="_new">RSS feed</a> or by <a href="http://feedburner.google.com/fb/a/mailverify?uri=WebInternationalAwards&#038;loc=en_US" target="_new">email</a>, because a new series will start soon. This new series will be around coding the same webapp using JSP on Tomcat.
</p>]]></content:encoded>
			<wfw:commentRss>http://www.webia.info/articles/tutorials/building-a-live-news-blogging-system-in-php-spiced-with-html5-css3-and-jquery-sources/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building a live news blogging system in php. Spiced with HTML5, CSS3 and jQuery [end]</title>
		<link>http://www.webia.info/articles/tutorials/building-a-live-news-blogging-system-in-php-spiced-with-html5-css3-and-jquery-end/</link>
		<comments>http://www.webia.info/articles/tutorials/building-a-live-news-blogging-system-in-php-spiced-with-html5-css3-and-jquery-end/#comments</comments>
		<pubDate>Tue, 08 Jun 2010 13:51:29 +0000</pubDate>
		<dc:creator>Bogdan Pop</dc:creator>
				<category><![CDATA[tutorials]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[live news system]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.webia.info/?p=1658</guid>
		<description><![CDATA[

Finally, the last part of the tutorial you have all been waiting for. Until now I've covered everything that deals with databases and the CRUD functionalities the system has. However, I haven't tackled the primary view of the app, the homepage, which automatically updates news as they are added in the database without requiring anything [...]]]></description>
			<content:encoded><![CDATA[<p class="imgpreview"><a href="http://www.webia.info/wp-content/uploads/2010/03/lns_preview_full.jpg" title="Tutorial app preview"><img src="http://www.webia.info/wp-content/uploads/2010/03/lnw_preview.jpg" alt="Tutorial app preview" /></a></p>
<p>
Finally, the last part of the tutorial you have all been waiting for. Until now I've covered everything that deals with databases and the CRUD functionalities the system has. However, I haven't tackled the primary view of the app, the homepage, which automatically updates news as they are added in the database without requiring anything from the end user. To bad I didn't finish the tutorial earlier; maybe some great online newspapers would have used it during yesterday's keynote address at WWDC.
</p>
<h2>HTML5 modifications, integration with php</h2>
<p>
In case you read all the previous parts of the tutorial, you know I used HTML5 to structure the layout of the app. While implementing some of the functionalities, small upgrades were required. I am going to start with the <em>head</em> of the document. There are two stylesheets added. One is for general styles, while the second one is used to style the datepicker used in the app and is the style that comes with jQuery's datepicker plugin. Having that said, you can see there's also the .js script for it and for jQuery as well. <em>date.js </em> is Jörn Zaefferer's and Brandon Aaron's date prototype extensions I've used in the app. The <em>sprinkle.js</em> file is where all the gizmoz performed by the app are stored.
</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;head&gt;
	&lt;title&gt;Live News System&lt;/title&gt;
	&lt;link rel=&quot;stylesheet&quot; href=&quot;css/style.css&quot; type=&quot;text/css&quot; media=&quot;screen&quot; title=&quot;no title&quot; charset=&quot;utf-8&quot;&gt;
	&lt;link rel=&quot;stylesheet&quot; href=&quot;css/datepicker.css&quot; type=&quot;text/css&quot; media=&quot;screen&quot; title=&quot;no title&quot; charset=&quot;utf-8&quot;&gt;
&nbsp;
	&lt;script src=&quot;js/jquery.js&quot; type=&quot;text/javascript&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;
	&lt;script src=&quot;js/date.js&quot; type=&quot;text/javascript&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;
	&lt;script src=&quot;js/datepicker.js&quot; type=&quot;text/javascript&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;
	&lt;script src=&quot;js/sprinkle.js&quot; type=&quot;text/javascript&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;	
&lt;/head&gt;</pre></td></tr></table></div>



<p>
Moving on to the body of the site the first items contained in the body are hidden to public view. It's a small php script that includes the functions file and calls for the initiateLastID() function. This function is newly added, and its code is provided just below.
</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">&lt;body&gt;
&nbsp;
	<span style="color: #000000; font-weight: bold;">&lt;?</span> <span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;includes/functions.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	   initiateLastID<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
	&lt;header class=&quot;top-rounded&quot;&gt;
		Live News System &lt;!-- The title of our app --&gt;         
	&lt;/header&gt;</pre></td></tr></table></div>





<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> initiateLastID<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">session_is_registered</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'lastID'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span> 
		<span style="color: #666666; font-style: italic;">// no previous call</span>
		<span style="color: #990000;">session_register</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'lastID'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT id FROM News WHERE id&gt;0 ORDER BY id DESC LIMIT 1&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'lastID'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$lastID</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>



<p>
What this function does is it creates a php session that contains the ID of the last news item added to the database. This session will be used to track new news added in the database while the user is on the homepage. This is a key variable in achieving a functionality similar to Twitter's new X items in search page.
</p>
<p>
Next, just after the details tag in the header of the page, the one which stores and displays information regarding selected filters, we add some more php code. The code is shown below and its purpose is to catch error and notification messages directly from the URL and display them nicely inside the webapp's UI.
</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>
<span style="color: #000088;">$msg</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$error</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$msg</span><span style="color: #339933;">=</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'msg'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$error</span><span style="color: #339933;">=</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'error'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$msg</span><span style="color: #339933;">!=</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;article class=&quot;no-hover message display&quot;&gt;
		&lt;h1&gt;<span style="color: #000000; font-weight: bold;">&lt;?=</span><span style="color: #000088;">$msg</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/h1&gt;
	&lt;/article&gt;
	<span style="color: #000000; font-weight: bold;">&lt;?</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$error</span><span style="color: #339933;">!=</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;article class=&quot;no-hover error display&quot;&gt;                      
		&lt;h1&gt;<span style="color: #000000; font-weight: bold;">&lt;?=</span><span style="color: #000088;">$error</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/h1&gt;
	&lt;/article&gt;
	<span style="color: #000000; font-weight: bold;">&lt;?</span>
<span style="color: #009900;">&#125;</span>
list_news<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>



<p>
<em>list_news()</em> is a bit complex, and will be presented in just a few minutes. 
</p>
<p>
In the right sidebar we have the start date and end date input fields. We need to store the information within these fields as users could accidentally click the refresh button of the web browser and loose data in those input fields. We protect the information in the fields by storing it using php sessions. The modified code for the two inputs is the following one:
</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;fieldset&gt;
	&lt;label for=&quot;start_date&quot;&gt;Start date: &lt;/label&gt;
	&lt;input type=&quot;text&quot; name=&quot;start_date&quot; value=&quot;&lt;?=$_SESSION['start']?&gt;&quot; id=&quot;start_date&quot; class=&quot;date-pick&quot;&gt;
	&lt;label for=&quot;end_date&quot;&gt;End date: &lt;/label&gt;
	&lt;input type=&quot;text&quot; name=&quot;end_date&quot; value=&quot;&lt;?=$_SESSION['end']?&gt;&quot; id=&quot;end_date&quot; class=&quot;date-pick&quot;&gt;
&lt;/fieldset&gt;</pre></td></tr></table></div>



<p>
Just below the two date inputs the categories of the webapp are listed. This is achieved by using a php function: <em>list_categories()</em> which was presented in the <a href="http://www.webia.info/articles/tutorials/building-a-live-news-blogging-system-in-php-spiced-with-html5-css3-and-jquery-part-iii/">third part of the tutorial</a>. However, during that part the function returned <em>option</em> values for <em>select</em> tags. The updated function is shown below.
</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;ul&gt;&lt;!-- This UL will hold our categories --&gt;
	&lt;li class=&quot;title&quot;&gt;Browse by category&lt;/li&gt;                     
	&lt;? list_categories(&quot;&quot;) ?&gt;
&lt;/ul&gt;</pre></td></tr></table></div>





<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> list_categories<span style="color: #009900;">&#40;</span><span style="color: #000088;">$mode</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">session_is_registered</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'categories'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$categories</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'categories'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$rows</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT name FROM Categories WHERE id&gt;0 ORDER BY name ASC&quot;</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$mode</span><span style="color: #339933;">==</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_num_rows</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rows</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_row</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rows</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">session_is_registered</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'categories'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> 
					<span style="color: #009900;">&#123;</span>
						<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$categories</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
						<span style="color: #009900;">&#123;</span>
							<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array_key_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #000088;">$categories</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;li&gt;&lt;a class=<span style="color: #000099; font-weight: bold;">\&quot;</span>selected-aside<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/a&gt;&lt;/li&gt;&quot;</span><span style="color: #339933;">;</span>
								<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;li&gt;&lt;a&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/a&gt;&lt;/li&gt;&quot;</span><span style="color: #339933;">;</span>
						<span style="color: #009900;">&#125;</span>
						<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;li&gt;&lt;a&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/a&gt;&lt;/li&gt;&quot;</span><span style="color: #339933;">;</span>
					<span style="color: #009900;">&#125;</span>
				<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;li&gt;&lt;a&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/a&gt;&lt;/li&gt;&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;li&gt;no categories&lt;/li&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$mode</span><span style="color: #339933;">==</span><span style="color: #0000ff;">&quot;select-options&quot;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// code in part three of the tutorial</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>



<p>
What the function does is find out which categories are already selected by the user, then display them as <em>list</em> items. If some of them are selected, the <em>selected-aside </em>class is appended to the <em>li</em> tag. Moreover, the <em>$mode</em> param used in this function determines if the function should return <em>li</em> tags or <em>option</em> tags.
</p>
<p>
The footer has also been updated and now tracks user login and displays information accordingly.
</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;footer&gt;
	&lt;? if(!session_is_registered('loggedin')) { ?&gt;&lt;a rel=&quot;login&quot; name=&quot;modal&quot;&gt;Admin login&lt;/a&gt; &lt;? } else { ?&gt;You are logged in. You can &lt;A  href=&quot;#addnews&quot; rel=&quot;addnews&quot; name=&quot;modal&quot;&gt;add news&lt;/a&gt; or &lt;a href=&quot;logout.php&quot; target=&quot;_self&quot;&gt;logout&lt;/a&gt;&lt;? } ?&gt;
&lt;/footer&gt;</pre></td></tr></table></div>



<p>
With this we've finished the HTML structure and content of the index page. Before moving on to the jQuery code which is used to add all the awesome functionalities let me remind you what the structure of an <em>article </em> is (referring to HTML article tag). Just below are presented two different structures, one used for showcasing news to end users while the second is used to display the news to admins that are logged in.
</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;article&gt;	
	&lt;h1&gt;news title&lt;/h1&gt;
	&lt;details&gt;Posted by &lt;span&gt;user&lt;/span&gt; in &lt;span class=&quot;cat&quot;&gt;category&lt;/span&gt; on &lt;span&gt;date&lt;/span&gt; at &lt;span&gt;time&lt;/span&gt;.&lt;/details&gt;
	&lt;p&gt;content of news&lt;/p&gt;
&lt;/article&gt;</pre></td></tr></table></div>





<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;article&gt;
	&lt;span class=&quot;controls&quot;&gt;&lt;a href=&quot;deletenews.php?id=ID&quot; target=&quot;_self&quot; class=&quot;delete&quot;&gt;&lt;/a&gt;&lt;a href=&quot;&quot; name=&quot;modal&quot; rel=&quot;editform&quot; title=&quot;ID&quot; target=&quot;_self&quot; class=&quot;edit&quot;&gt;&lt;/a&gt;&lt;/span&gt;	
	&lt;h1&gt;news title&lt;/h1&gt;
	&lt;details&gt;Posted by &lt;span&gt;user&lt;/span&gt; in &lt;span class=&quot;cat&quot;&gt;category&lt;/span&gt; on &lt;span&gt;date&lt;/span&gt; at &lt;span&gt;time&lt;/span&gt;.&lt;/details&gt;
	&lt;p&gt;content of news&lt;/p&gt;
&lt;/article&gt;</pre></td></tr></table></div>



<p>
As you can see the code used for admins contains an extra <em>span</em> with links to the edit and delete buttons for the news item. 
</p>
<h2>list_news()</h2>
<p>
Based on the average complexity of the functions presented up to this point, this function that spans across 100 lines of code is huge. Check out the code, try to understand it. Explanations will follow just after it.
</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> list_news<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$categories_query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">session_is_registered</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'categories'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// we have some registered categories, so our query will not select all news</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'categories'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$categorieskeys</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_keys</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'categories'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$count</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$categorieskeys</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
				<span style="color: #009900;">&#123;</span>
					<span style="color: #000088;">$categories_query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;AND (&quot;</span><span style="color: #339933;">;</span>
					<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$categorieskeys</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$count</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">!=</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
					<span style="color: #009900;">&#123;</span>
						<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$count</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$categories_query</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$categories_query</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; OR category = '&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$categorieskeys</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$count</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;' &quot;</span><span style="color: #339933;">;</span>
						<span style="color: #b1b100;">else</span> <span style="color: #000088;">$categories_query</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$categories_query</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; category = '&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$categorieskeys</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$count</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;' &quot;</span><span style="color: #339933;">;</span>
						<span style="color: #000088;">$count</span><span style="color: #339933;">++;</span>
					<span style="color: #009900;">&#125;</span>
					<span style="color: #000088;">$categories_query</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$categories_query</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; ) &quot;</span><span style="color: #339933;">;</span>				
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000088;">$start</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'start'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$end</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'end'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>	
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$categories_query</span><span style="color: #339933;">!=</span><span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">session_is_registered</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'start'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">session_is_registered</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'end'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$start</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">!=</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$end</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">!=</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT * FROM News WHERE id&gt;0 &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$categories_query</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; AND  publishing_date &gt;= '<span style="color: #006699; font-weight: bold;">$start</span>' AND publishing_date &lt;='<span style="color: #006699; font-weight: bold;">$end</span>' ORDER BY publishing_date DESC, publishing_time DESC&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">session_is_registered</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'start'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$start</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">!=</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT * FROM News WHERE id&gt;0 &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$categories_query</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; AND publishing_date &gt;= '<span style="color: #006699; font-weight: bold;">$start</span>' ORDER BY publishing_date DESC, publishing_time DESC&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">session_is_registered</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'end'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$end</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">!=</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT * FROM News WHERE id&gt;0 &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$categories_query</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; AND publishing_date &lt;= '<span style="color: #006699; font-weight: bold;">$end</span>' ORDER BY publishing_date DESC, publishing_time DESC&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">else</span> <span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT * FROM News WHERE id&gt;0 &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$categories_query</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; ORDER BY publishing_date DESC, publishing_time DESC&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> 
	<span style="color: #b1b100;">else</span> 
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">session_is_registered</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'start'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">session_is_registered</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'end'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$start</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">!=</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$end</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">!=</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT * FROM News WHERE id&gt;0 AND  publishing_date &gt;= '<span style="color: #006699; font-weight: bold;">$start</span>' AND publishing_date &lt;= '<span style="color: #006699; font-weight: bold;">$end</span>' ORDER BY publishing_date DESC, publishing_time DESC&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">session_is_registered</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'start'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$start</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">!=</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT * FROM News WHERE id&gt;0 AND publishing_date &gt;= '<span style="color: #006699; font-weight: bold;">$start</span>' ORDER BY publishing_date DESC, publishing_time DESC&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">session_is_registered</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'end'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$end</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">!=</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT * FROM News WHERE id&gt;0 AND publishing_date &lt;= '<span style="color: #006699; font-weight: bold;">$end</span>' ORDER BY publishing_date DESC, publishing_time DESC&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">else</span> <span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT * FROM News WHERE id&gt;0 ORDER BY publishing_date DESC, publishing_time DESC&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000088;">$newlastID</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$rows</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">// row contains ID title body owner publishing_date publishing_time category</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_num_rows</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rows</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_row</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rows</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$newlastID</span><span style="color: #339933;">==</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> 
			<span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$newlastID</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">session_is_registered</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'lastID'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
				<span style="color: #009900;">&#123;</span> 
					<span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'lastID'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$newlastID</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$lastID</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$newlastID</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
				<span style="color: #b1b100;">else</span>
				<span style="color: #009900;">&#123;</span> 
					<span style="color: #666666; font-style: italic;">// no previous call</span>
					<span style="color: #990000;">session_register</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'lastID'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'lastID'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$lastID</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>				
			<span style="color: #009900;">&#125;</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">session_is_registered</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'loggedin'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$admincontrols</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;span class=<span style="color: #000099; font-weight: bold;">\&quot;</span>controls<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&lt;a href=<span style="color: #000099; font-weight: bold;">\&quot;</span>deletenews.php?id=&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span> target=<span style="color: #000099; font-weight: bold;">\&quot;</span>_self<span style="color: #000099; font-weight: bold;">\&quot;</span> class=<span style="color: #000099; font-weight: bold;">\&quot;</span>delete<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&lt;/a&gt;&lt;a href=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #000099; font-weight: bold;">\&quot;</span> name=<span style="color: #000099; font-weight: bold;">\&quot;</span>modal<span style="color: #000099; font-weight: bold;">\&quot;</span> rel=<span style="color: #000099; font-weight: bold;">\&quot;</span>editform<span style="color: #000099; font-weight: bold;">\&quot;</span> title=<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span> target=<span style="color: #000099; font-weight: bold;">\&quot;</span>_self<span style="color: #000099; font-weight: bold;">\&quot;</span> class=<span style="color: #000099; font-weight: bold;">\&quot;</span>edit<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&lt;/a&gt;&lt;/span&gt;&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;
				&lt;article&gt;
					&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$admincontrols</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;
					&lt;h1&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/h1&gt;
					&lt;details&gt;Posted by &lt;span&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/span&gt; in &lt;span class=<span style="color: #000099; font-weight: bold;">\&quot;</span>cat<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">6</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/span&gt; on &lt;span&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/span&gt; at &lt;span&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/span&gt;.&lt;/details&gt;
					&lt;p&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/p&gt;
				&lt;/article&gt;
			&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;article class=<span style="color: #000099; font-weight: bold;">\&quot;</span>no-hover<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&lt;h1&gt;No news into the system&lt;/h1&gt;&lt;/article&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>



<p>
The first section of the function starting on the <em>third line and going up to line 22</em> checks if there are any categories selected. If at least one is selected the code builds a SQL statement which will be used in a SELECT / WHERE clause.
</p>
<p>
The code on <em>lines 24 and 25</em> is used to check whether the start and end dates used for news filtering are enabled. If they are enabled they must to be used in the SELECT statement against the database.
</p>
<p>
First batch of SELECT statements, starting on <em>line 27 up to 42</em>. This batch is used if the users have selected any categories to filter the results. There are multiple statements because each one of them is used based on start and end date filters contents. The second batch, <em>line 45 to 57</em>, does the same thing as the above batch, but doesn't limit the results based on categories because in this case none of them is selected.
</p>
<p>
The code between <em>lines 60 to 94</em> lists the results of the previous SQL queries. <em>$newlastID</em> variable is used to update the $lastID session described above. This is necessary because the ID of the last news added to the system changes as soon as applied filters change. The last news in one category doesn't have the same ID as the last news inside another category, or throughout the entire system. These checks and session updates are done between <em>lines 68 and 82</em> and are done once per each query.
</p>
<p>
Finally, the code from <em>line 83 to 90</em> is used to create the structure and content of each news item and display it.
</p>
<p>
Further more, there's another similar function as complex as this one. Its name is <em>list_new_news()</em> and the difference between this one and the one presented above is that it uses the <em>lastID</em> session in its SELECT statements, returning items which have an ID bigger than what <em>lastID</em> stores. This function is used to add to the DOM news items that were added to the system after the user has loaded the page. 
</p>
<p>
Basically, this function is used to achieve the functionality of the Twitter new items feature available in Twitter's search page. However, simply coding it won't do any good. This function has to be combined with some ajax requests, which are coded in the <em>sprinkle.js</em> jQuery file.
</p>
<h2>sprinkle.js</h2>
<p>
Thank God I've shown parts of this file in the previous five parts of the tutorial. Otherwise, the task for today would have been explaining 400 or more lines of code. Fortunately, some of them are already known so I am going to stick to showing the newly added lines only.
</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> updateNews<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	$.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'includes/check_new_items.php'</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>newdata<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>newdata.<span style="color: #660066;">length</span><span style="color: #339933;">==</span><span style="color: #CC0000;">3</span><span style="color: #009900;">&#41;</span> 
		<span style="color: #009900;">&#123;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#newdata'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">insertAfter</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'section &gt; details'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
		<span style="color: #006600; font-style: italic;">// find out each new article, compute height, and set new heights for section and aside</span>
		<span style="color: #003366; font-weight: bold;">var</span> sectionHeight <span style="color: #339933;">=</span> <span style="color: #CC0000;">75</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// padding, margin, included elements</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'section article'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			sectionHeight <span style="color: #339933;">=</span> sectionHeight <span style="color: #339933;">+</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">height</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">10</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">25</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// 10 comes from padding t b, 25 from margin top</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		asideHeight <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
		asideHeight <span style="color: #339933;">=</span> asideHeight <span style="color: #339933;">+</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'aside div'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">height</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'aside li'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			asideHeight <span style="color: #339933;">=</span> asideHeight <span style="color: #339933;">+</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">height</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'class'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #3366CC;">'title'</span><span style="color: #009900;">&#41;</span> asideHeight <span style="color: #339933;">=</span> asideHeight <span style="color: #339933;">+</span> <span style="color: #CC0000;">15</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>asideHeight <span style="color: #339933;">&lt;</span> sectionHeight<span style="color: #009900;">&#41;</span> 
		<span style="color: #009900;">&#123;</span>
		<span style="color: #006600; font-style: italic;">//	alert (sectionHeight);</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'aside, section'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> height<span style="color: #339933;">:</span> sectionHeight <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span>queue<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// update height	</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000066; font-weight: bold;">else</span>
		<span style="color: #009900;">&#123;</span>
		<span style="color: #006600; font-style: italic;">//	alert (asideHeight);</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'aside, section'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> height<span style="color: #339933;">:</span> asideHeight <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span>queue<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// update height	</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #006600; font-style: italic;">// done with column heights</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'section article'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeIn</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'slow'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>



<p>
The above function checks for new news added into the database. If new items are available, a message stating so is appended to the DOM. If the message box is clicked new news items are appended to the DOM and then faded in so that users can see them. This functions's corresponding php file is similar to the list_news() function. What is changed is the last part of the function which displays the news items, part that has been replaced with the code shown below:
</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$newLastID</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$nothere</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$rows</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// row contains ID title body owner publishing_date publishing_time category</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_num_rows</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rows</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_row</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rows</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$newLastID</span><span style="color: #339933;">==</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$newLastID</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$oldLastID</span><span style="color: #339933;">&lt;</span><span style="color: #000088;">$newLastID</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$nothere</span><span style="color: #339933;">==</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;new&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$nothere</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>



<p>
The following code is used to handle clicks performed on the categories listed in the sidebar. What the code does is it checks whether the clicked category is selected. If it is, the category is removed from the php categories session and its visual style changed. If the category is not selected it is appended to the php categories session and its visual appearance changed. The php file that's used to update the session is also shown below:
</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// change style for aside category selector and filters above content + ajax requests for updating selected categories</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;aside ul li a&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> classAttr <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'class'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>classAttr <span style="color: #339933;">!=</span> <span style="color: #3366CC;">'selected-aside'</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #006600; font-style: italic;">// update style class for category just clicked</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'class'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'selected-aside'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> category <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;span&gt;X&lt;/span&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		 <span style="color: #006600; font-style: italic;">// check filter legend status and update it if required</span>
		<span style="color: #003366; font-weight: bold;">var</span> classAttr <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.categories'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'class'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>classAttr <span style="color: #339933;">==</span> <span style="color: #3366CC;">'categories not-selected'</span><span style="color: #009900;">&#41;</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.categories'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'class'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'categories selected'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #006600; font-style: italic;">// now we need to make an ajax call to add our category to our selected categories session</span>
		<span style="color: #003366; font-weight: bold;">var</span> jdata <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;function=add&amp;category=&quot;</span><span style="color: #339933;">+</span>category<span style="color: #339933;">;</span> 
		$.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
			type<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;POST&quot;</span><span style="color: #339933;">,</span>
			url<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;includes/categories_sessions.php&quot;</span><span style="color: #339933;">,</span>
 				data<span style="color: #339933;">:</span> jdata 
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">else</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #006600; font-style: italic;">// update style class for category just clicked</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'class'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> span <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span>span<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> category <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #006600; font-style: italic;">// now we need to make an ajax call to remove our category to our selected categories session</span>
		<span style="color: #003366; font-weight: bold;">var</span> jdata <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;function=remove&amp;category=&quot;</span><span style="color: #339933;">+</span>category<span style="color: #339933;">;</span> 
		$.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
			type<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;POST&quot;</span><span style="color: #339933;">,</span>
			url<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;includes/categories_sessions.php&quot;</span><span style="color: #339933;">,</span>
 				data<span style="color: #339933;">:</span> jdata 
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #006600; font-style: italic;">// check if there is any category selected</span>
		<span style="color: #006600; font-style: italic;">// if not, update filter legend class</span>
		<span style="color: #003366; font-weight: bold;">var</span> anyCatSelected <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.selected-aside'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>anyCatSelected<span style="color: #339933;">==</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> 
		<span style="color: #009900;">&#123;</span>	
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.categories'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'class'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'categories not-selected'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #006600; font-style: italic;">// from else</span></pre></td></tr></table></div>





<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>
	<span style="color: #990000;">session_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #000088;">$err</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'function'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$function</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'function'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">else</span> <span style="color: #000088;">$err</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'category'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$category</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'category'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">else</span> <span style="color: #000088;">$err</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$err</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span> 
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$function</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'add'</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span> 
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">session_is_registered</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'categories'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span> 
				<span style="color: #000088;">$categories</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'categories'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$categories</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$category</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'categories'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$categories</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #b1b100;">else</span>
			<span style="color: #009900;">&#123;</span> 
				<span style="color: #666666; font-style: italic;">// no previous call</span>
				<span style="color: #990000;">session_register</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'categories'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$categories</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$categories</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$category</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'categories'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$categories</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$function</span>  <span style="color: #339933;">==</span> <span style="color: #0000ff;">'remove'</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$categories</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'categories'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$categories</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$category</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'categories'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$categories</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>



<p>
However, we're not done yet with the functionality. If someone changes the categories which are selected the news must be updated and the following code does that:
</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// ajax requests to reload content and resize section + aside</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'section article'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeOut</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'slow'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> 
		<span style="color: #006600; font-style: italic;">// completion of fading current content out</span>
		<span style="color: #006600; font-style: italic;">//$('section').animate({ height: sectionHeight });  // reset height of section to original value</span>
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'section article'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">length</span><span style="color: #339933;">&gt;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'section article'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> oldcontent <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'section'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		$.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'includes/load_news.php'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>newdata<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'section'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>oldcontent<span style="color: #339933;">+</span>newdata<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #006600; font-style: italic;">// find out each new article, compute height, and set new heights for section and aside</span>
			<span style="color: #003366; font-weight: bold;">var</span> sectionHeight <span style="color: #339933;">=</span> <span style="color: #CC0000;">50</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// padding, margin, included elements</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'section article'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				sectionHeight <span style="color: #339933;">=</span> sectionHeight <span style="color: #339933;">+</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">height</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">10</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">25</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// 10 comes from padding t b, 25 from margin top</span>
			<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			asideHeight <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
			asideHeight <span style="color: #339933;">=</span> asideHeight <span style="color: #339933;">+</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'aside div'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">height</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'aside li'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				asideHeight <span style="color: #339933;">=</span> asideHeight <span style="color: #339933;">+</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">height</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'class'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #3366CC;">'title'</span><span style="color: #009900;">&#41;</span> asideHeight <span style="color: #339933;">=</span> asideHeight <span style="color: #339933;">+</span> <span style="color: #CC0000;">15</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>asideHeight <span style="color: #339933;">&lt;</span> sectionHeight<span style="color: #009900;">&#41;</span> 
			<span style="color: #009900;">&#123;</span>
			<span style="color: #006600; font-style: italic;">//	alert (sectionHeight);</span>
				$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'aside, section'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> height<span style="color: #339933;">:</span> sectionHeight <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span>queue<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// update height	</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000066; font-weight: bold;">else</span>
			<span style="color: #009900;">&#123;</span>
			<span style="color: #006600; font-style: italic;">//	alert (asideHeight);</span>
				$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'aside, section'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> height<span style="color: #339933;">:</span> asideHeight <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span>queue<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// update height	</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #006600; font-style: italic;">// done with column heights</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'section article'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeIn</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'slow'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			overlay<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>



<p>
Based on the request processed by the <em>load_news.php</em> file we'll probably have to change the content that's visible on the homepage. Therefore, current content is faded out, new content inserted and main content area and sidebar heights updated. Only after these processes are completed the new content is faded in and displayed in the page. The <em>load_news.php</em> file simply calls the <em>load_news()</em> function.
</p>
<p>
Same content reloading has to take place if users change the date range they want via the two datepickers located in the top of the right sidebar. The process is the same as the one described above in the case of categories being changed with a simple addition to the code. The new addition is the request processed by the <em>datepicker.php</em> file which does some session updating and nothing more. The differences are shown below:
</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#start_date'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">change</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #006600; font-style: italic;">// the start date of date picker has been changed</span>
	<span style="color: #006600; font-style: italic;">// ajax call to handle it</span>
	<span style="color: #003366; font-weight: bold;">var</span> startdate <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>startdate<span style="color: #339933;">!=</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> classAttr <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.daterange'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'class'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>classAttr <span style="color: #339933;">==</span> <span style="color: #3366CC;">'daterange not-selected'</span><span style="color: #009900;">&#41;</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.daterange'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'class'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'daterange selected'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
&nbsp;
			<span style="color: #003366; font-weight: bold;">var</span> jdata <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;function=start&amp;date=&quot;</span><span style="color: #339933;">+</span>startdate<span style="color: #339933;">;</span> 
			$.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
				type<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;POST&quot;</span><span style="color: #339933;">,</span>
				url<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;includes/datepicker.php&quot;</span><span style="color: #339933;">,</span>
				data<span style="color: #339933;">:</span> jdata 
			<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #006600; font-style: italic;">// load_news.php request as presented above in the tutorial</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#end_date'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">change</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #006600; font-style: italic;">// the start date of date picker has been changed</span>
	<span style="color: #006600; font-style: italic;">// ajax call to handle it</span>
	<span style="color: #003366; font-weight: bold;">var</span> enddate <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>enddate<span style="color: #339933;">!=</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> classAttr <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.daterange'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'class'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>classAttr <span style="color: #339933;">==</span> <span style="color: #3366CC;">'daterange not-selected'</span><span style="color: #009900;">&#41;</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.daterange'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'class'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'daterange selected'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
&nbsp;
			<span style="color: #003366; font-weight: bold;">var</span> jdata <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;function=end&amp;date=&quot;</span><span style="color: #339933;">+</span>enddate<span style="color: #339933;">;</span> 
			$.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
				type<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;POST&quot;</span><span style="color: #339933;">,</span>
				url<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;includes/datepicker.php&quot;</span><span style="color: #339933;">,</span>
				data<span style="color: #339933;">:</span> jdata 
			<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #006600; font-style: italic;">// load_news.php request as presented above in the tutorial</span>
	<span style="color: #009900;">&#125;</span>	
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>





<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>
	<span style="color: #990000;">session_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #000088;">$err</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'function'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$function</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'function'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">else</span> <span style="color: #000088;">$err</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'date'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$date</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'date'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">else</span> <span style="color: #000088;">$err</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$err</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span> 
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$function</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'start'</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span> 
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">session_is_registered</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'start'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span> 
				<span style="color: #000088;">$start</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'start'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$start</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$date</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'start'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$start</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #b1b100;">else</span>
			<span style="color: #009900;">&#123;</span> 
				<span style="color: #666666; font-style: italic;">// no previous call</span>
				<span style="color: #990000;">session_register</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'start'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$start</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'start'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$start</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$date</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'start'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$start</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$function</span>  <span style="color: #339933;">==</span> <span style="color: #0000ff;">'end'</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">session_is_registered</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'end'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span> 
				<span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'end'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$date</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #b1b100;">else</span>
			<span style="color: #009900;">&#123;</span> 
				<span style="color: #666666; font-style: italic;">// no previous call</span>
				<span style="color: #990000;">session_register</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'end'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'end'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$date</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$function</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'clear'</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$start</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'start'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$start</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'start'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$start</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #000088;">$end</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'end'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$end</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'end'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$end</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>	
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>



<p>
How do we actually handle new news items. During the first part of the series a hidden div was added to the page structure, which was supposed to be used on a later time. That time has come; let me remind you that small piece of HTML:
</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;article class=&quot;no-hover hidden&quot; id=&quot;newdata&quot;&gt;
	&lt;h1&gt;New articles in the system. Click here to view them&lt;/h1&gt;  
&lt;/article&gt;</pre></td></tr></table></div>



<p>
The above div is hidden but it fades in on top of all the articles if ajax requests show that new items are available in the database and they correspond with user's filters. Checking is the task of the <em> updateNews()</em> function which uses the <em>check_new_items.php</em> file. If new items are available the #newdata div is added on top of the articles displayed in the page, just as described above when the updateNews() function was shown. Here's the code that handles the clicks performed on this div and that fades out current content and displays new news items:
</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#newdata'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#newdata'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">insertAfter</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'footer'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#newdata'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeAttr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'style'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// ajax requests to reload content and resize section + aside</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'section article'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeOut</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'slow'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> 
				<span style="color: #006600; font-style: italic;">// completion of fading current content out</span>
				<span style="color: #006600; font-style: italic;">//$('section').animate({ height: sectionHeight });  // reset height of section to original value</span>
				<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'section article'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">length</span><span style="color: #339933;">&gt;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'section article'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #003366; font-weight: bold;">var</span> oldcontent <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'section'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				$.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'includes/load_new_news.php'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>newdata<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
					$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'section'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>oldcontent<span style="color: #339933;">+</span>newdata<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
					<span style="color: #006600; font-style: italic;">// find out each new article, compute height, and set new heights for section and aside</span>
					<span style="color: #003366; font-weight: bold;">var</span> sectionHeight <span style="color: #339933;">=</span> <span style="color: #CC0000;">75</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// padding, margin, included elements</span>
					$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'section article'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
						sectionHeight <span style="color: #339933;">=</span> sectionHeight <span style="color: #339933;">+</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">height</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">10</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">25</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// 10 comes from padding t b, 25 from margin top</span>
					<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					asideHeight <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
					asideHeight <span style="color: #339933;">=</span> asideHeight <span style="color: #339933;">+</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'aside div'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">height</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'aside li'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
						asideHeight <span style="color: #339933;">=</span> asideHeight <span style="color: #339933;">+</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">height</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'class'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #3366CC;">'title'</span><span style="color: #009900;">&#41;</span> asideHeight <span style="color: #339933;">=</span> asideHeight <span style="color: #339933;">+</span> <span style="color: #CC0000;">15</span><span style="color: #339933;">;</span>
					<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
					<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>asideHeight <span style="color: #339933;">&lt;</span> sectionHeight<span style="color: #009900;">&#41;</span> 
					<span style="color: #009900;">&#123;</span>
					<span style="color: #006600; font-style: italic;">//	alert (sectionHeight);</span>
						$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'aside, section'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> height<span style="color: #339933;">:</span> sectionHeight <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span>queue<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// update height	</span>
					<span style="color: #009900;">&#125;</span>
					<span style="color: #000066; font-weight: bold;">else</span>
					<span style="color: #009900;">&#123;</span>
					<span style="color: #006600; font-style: italic;">//	alert (asideHeight);</span>
						$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'aside, section'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> height<span style="color: #339933;">:</span> asideHeight <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span>queue<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// update height	</span>
					<span style="color: #009900;">&#125;</span>
					<span style="color: #006600; font-style: italic;">// done with column heights</span>
					$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'section article'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeIn</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'slow'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					overlay<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>



<p>
You'd think that this is all the code we need. Unfortunately, it isn't. Just placing the updateNews() function won't make wonders. We need to call this function on a set interval, 5 or 10 seconds for example. This way the users do not have to reload the page to check for new news as the app periodically checks that for them and displays a notification message if new items are added. The users only have to sit back and enjoy the feed. The code that creates the 10 second loop call of the function is shown below:
</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">setInterval<span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;updateNews()&quot;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">10000</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>



<h2>Conclusion</h2>
<p>
The webapp could be used to live blog different important events, such as WWDC, Oscars and so on. Moreover, due to the categories filters one could live blog different events simultaneously on the same app.
</p>
<h2>Source code and demo</h2>
<p>
As you know from the <a href="http://www.webia.info/articles/tutorials/building-a-live-news-blogging-system-in-php-spiced-with-html5-css3-and-jquery-demo/">demo part of the tutorial</a> a demo of the application is available <a href="http://demos.webia.info/news_system">over here</a>. I am working on packing the source codes and they should be available to download, use and extend soon!
</p>
<p>
If you liked this tutorial series, stay updated to new content via our <a href="http://feeds2.feedburner.com/WebInternationalAwards" target="_new">RSS feed</a> or by <a href="http://feedburner.google.com/fb/a/mailverify?uri=WebInternationalAwards&#038;loc=en_US" target="_new">email</a>, because a new series will start soon. This new series will be around coding the same webapp using JSP on Tomcat.
</p>]]></content:encoded>
			<wfw:commentRss>http://www.webia.info/articles/tutorials/building-a-live-news-blogging-system-in-php-spiced-with-html5-css3-and-jquery-end/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Keep it simple</title>
		<link>http://www.webia.info/articles/usability/keep-it-simple/</link>
		<comments>http://www.webia.info/articles/usability/keep-it-simple/#comments</comments>
		<pubDate>Tue, 01 Jun 2010 08:00:33 +0000</pubDate>
		<dc:creator>Bogdan Pop</dc:creator>
				<category><![CDATA[usability]]></category>
		<category><![CDATA[effective]]></category>
		<category><![CDATA[fast]]></category>
		<category><![CDATA[keep]]></category>
		<category><![CDATA[kiss]]></category>
		<category><![CDATA[professional]]></category>
		<category><![CDATA[satisfy]]></category>
		<category><![CDATA[simple]]></category>

		<guid isPermaLink="false">http://www.webia.info/?p=1649</guid>
		<description><![CDATA[
Whether you're developing a webapp, a website, some native software or a simple installer, keep it simple and straightforward. We barely have time for anything these days, and effective solutions that help us doing what we need to do fast, without error will win over pretty much anything else.


This concept applies to web forms, navigation, [...]]]></description>
			<content:encoded><![CDATA[<p>
Whether you're developing a webapp, a website, some native software or a simple installer, keep it simple and straightforward. We barely have time for anything these days, and effective solutions that help us doing what we need to do fast, without error will win over pretty much anything else.
</p>
<p>
This concept applies to web forms, navigation, software options, and more. The faster the users get things done, the more satisfied they will feel, they'll use your solution even more and refer others to it. This post will be best suited in a thoughts / tumblr blog, but I figured it may get in here as well. 
</p>
<h2>Inspiration</h2>
<p>
This post was inspired from the recent Windows encounters I've had. Remember the post on <a href="http://www.webia.info/articles/usability/key-usability-in-web-forms">web forms usability</a> published just a while ago? Well, while installing the Microsoft Office Suite downloaded after using that faulty web form, I got a new installation wizard out of the blue, which I didn't ask for.
</p>
<p class="imgpreview"><a href="http://www.webia.info/wp-content/uploads/2010/05/select_components_to_install.jpg" title="Microsoft installer asking to select unique component to be installed"><img src="http://www.webia.info/wp-content/uploads/2010/05/select_components_to_install.jpg" alt="Microsoft installer asking to select unique component to be installed" /></a></p>
<p>
For some reason, I was asked to install Business contact Manager for Outlook Express 2007. I have no idea what that is, but I assume what it's used for. Bottom line is I don't need it. On top of that is the really bad installer.
</p>
<p> Let's assume someone wants to actually install it. The installer starts and shows one component that can be installed. The one I want. Why would you not simply let me get through with the process and require me to select the component to be installed. After all, moments ago I double clicked to install it? Why confirm that again? 
</p>
<p class="imgpreview"><a href="http://www.webia.info/wp-content/uploads/2010/05/select_components_to_install_next.jpg" title="Microsoft installer with enabled next button only after unique component is selected"><img src="http://www.webia.info/wp-content/uploads/2010/05/select_components_to_install_next.jpg" alt="Microsoft installer with enabled next button only after unique component is selected" /></a></p>
<p>
What's even worse is that I cannot click the Next button until I select the unique component. Moreover, there isn't a "finish" installation button. It's a "Next" step button. I don't want to waste any more steps with this issue. Just let me get on with it.
</p>
<p>
To conclude, whatever you're doing, try to keep it simple and straightforward for your users. Don't frustrate them with never ending jibberish chat.
</p>]]></content:encoded>
			<wfw:commentRss>http://www.webia.info/articles/usability/keep-it-simple/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Key usability in web forms</title>
		<link>http://www.webia.info/articles/usability/key-usability-in-web-forms/</link>
		<comments>http://www.webia.info/articles/usability/key-usability-in-web-forms/#comments</comments>
		<pubDate>Tue, 25 May 2010 13:00:38 +0000</pubDate>
		<dc:creator>Bogdan Pop</dc:creator>
				<category><![CDATA[usability]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[fields]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[guidelines]]></category>
		<category><![CDATA[mandatory]]></category>
		<category><![CDATA[optional]]></category>
		<category><![CDATA[practice]]></category>
		<category><![CDATA[required]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.webia.info/?p=1636</guid>
		<description><![CDATA[

Two of the most popular articles published here deal with web forms. The first one is around the theoretical aspects of web forms while the second one resides along the practical issues, coding and validating web forms. This article blends some concepts from both articles and showcases a key error that mustn't be in your [...]]]></description>
			<content:encoded><![CDATA[<p class="imgpreview"><a href="http://www.webia.info/wp-content/uploads/2010/05/forms_usability_required_big.png" title="Microsoft's form displaying errors for required / not required fields. Who knows?"><img src="http://www.webia.info/wp-content/uploads/2010/05/forms_usability_required_small.jpg" alt="Microsoft's form displaying errors for required / not required fields. Who knows?" /></a></p>
<p>
Two of the most popular articles published here deal with web forms. The first one is around the <a href="http://www.webia.info/articles/usability/forms-cant-live-with-them-cant-live-without-them/">theoretical aspects of web forms</a> while the second one resides along the practical issues, <a href="http://www.webia.info/articles/usability/impressive-web-forms-from-coding-to-validation/">coding and validating web forms</a>. This article blends some concepts from both articles and showcases a key error that mustn't be in your web forms.
</p>
<h2>The issues with required fields</h2>
<p>
The issue with required fields is that there shouldn't be any required fields on a web form. Don't place asterisks to label required fields. Nobody follows that pattern, though most users expect a field to be required if it has one asterisk appended to its label. If you have a web form that requires user's email, password, first and last names, don't put asterisks or any other messages. Just put the inputs in the form and the user will fill them.
</p>
<p>
Moreover, if you have those fields, don't place an asterisk only next to email and password and expect users to input their names as well. That will never happen! Following this pattern, after the user hits the submit button, don't display an error message telling them that the name fields are required as well, if you didn't point that out in the first place. This is usually something that will make visitors leave your website and never use your form, which was the primary goal for them upon arriving at that page.
</p>
<h2>That is total failure! Your mistake, not your user's!</h2>
<p>
Time to guess who has web forms with such flaws. It's Microsoft! The same company that has .exe executable download managers which users need to run to download any of their software. Mac users need to run them as well to download their operating system, for example, if they wish to switch to Windows, or use it virtually. But that's another story.
</p>
<h2>The moral</h2>
<p>
From time to time, I unfortunately need to use Microsoft Office and other Windows native software. Not my option though. While trying to download a trial version of the Office suite, I was asked to sign up on Microsoft's website. The form asked for my email, my desired password, first and last names, and my country. The first two we're marked as mandatory fields, while the rest weren't. The country field was a preselected select field, which I had nothing else to do but update.
</p>
<p>
After pressing the submit button, I wasn't taken to a download page. Instead, I was shown a couple of errors I've done. I haven't inputted any information in my name fields. But I didn't know I needed to. Thank god for Microsoft that the bid I was working on required specific documents (.docs) and I really needed to proceed, otherwise that would have been the end of my journey on their website.
</p>
<h2>Conclusion</h2>
<p>
Try to strip down the fields of your web forms. Not the required ones, but all fields. Don't ask for unnecessary information. Ask only mandatory information, and don't label it as mandatory. If your form is simple and short, users would be delighted to input what you're asking for.
</p>]]></content:encoded>
			<wfw:commentRss>http://www.webia.info/articles/usability/key-usability-in-web-forms/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Best of the best!</title>
		<link>http://www.webia.info/misc/best-of-the-best/</link>
		<comments>http://www.webia.info/misc/best-of-the-best/#comments</comments>
		<pubDate>Tue, 18 May 2010 11:02:53 +0000</pubDate>
		<dc:creator>Bogdan Pop</dc:creator>
				<category><![CDATA[misc]]></category>

		<guid isPermaLink="false">http://www.webia.info/?p=1627</guid>
		<description><![CDATA[
We've hit a really busy, rough couple of weeks at our company. Therefor, the final post of our blogging system tutorial will be published only next week as opposed to this one. However, this week we're going to remind you of our best articles which generated loads of traffic.

Make your own jQuery slider using XML



An [...]]]></description>
			<content:encoded><![CDATA[<p>
We've hit a really busy, rough couple of weeks at <a href="http://www.webraptor.eu/index_developers.php?c=webia">our company</a>. Therefor, the final post of our <a href="http://www.webia.info/articles/tutorials/building-a-live-news-blogging-system-in-php-spiced-with-html5-css3-and-jquery-part-i/">blogging system tutorial</a> will be published only next week as opposed to this one. However, this week we're going to remind you of our best articles which generated loads of traffic.
</p>
<h2><a href="http://www.webia.info/articles/tutorials/make-your-own-jquery-slider-using-xml/">Make your own jQuery slider using XML</a></h2>
<p class="imgpreview"><a href="http://www.webia.info/wp-content/uploads/2010/03/slider_screenshot_webraptor.jpg" title="Slider screenshot on the upcoming WebRaptor website"><img src="http://www.webia.info/wp-content/uploads/2010/03/slider_screenshot_webraptor.jpg" alt="Slider screenshot" /></a></p>
<p>
<p>
An awesome tutorial on how to build a custom jQuery slider that stores data in external XML files, which had a great follow up plugin: <a href="http://www.webia.info/articles/jquery-articles/awesome-slider-v1-0/">Awesome Slider</a></p>
</p>
<h2><a href="http://www.webia.info/articles/tutorials/building-a-live-news-blogging-system-in-php-spiced-with-html5-css3-and-jquery-part-i/">Building a live news blogging system in php. Spiced with HTML5, CSS3 and jQuery</a></h2>
<p class="imgpreview"><a href="http://www.webia.info/wp-content/uploads/2010/03/lns_preview_full.jpg" title="This is how the live news blogging system will look like in the end"><img src="http://www.webia.info/wp-content/uploads/2010/03/lnw_preview.jpg" alt="Live news system preview" /></a></p>
<p>
This is a great tutorial series that tackles many technologies and programming methodologies such as HTML5, CSS, PHP, MYSQL, jQuery, AJAX and more!
</p>
<h2><a href="http://www.webia.info/articles/usability/impressive-web-forms-from-coding-to-validation/">Impressive web forms. From coding to validation!</a></h2>
<p class="imgpreview"><a href="http://www.webia.info/wp-content/uploads/2010/03/webraptor_form_validation.jpg" title="Screenshot of WebRaptor's request quote form"><img src="http://www.webia.info/wp-content/uploads/2010/03/webraptor_form_validation.jpg" alt="Screenshot of WebRaptor's request quote form" /></a></p>
<p>
Ever wondered how to design, code, and validate beautiful web forms? This article is a must read!
</p>
<h2><a href="http://www.webia.info/articles/usability/forms-cant-live-with-them-cant-live-without-them/">Forms. Can't live with them. Can't live without them.</a></h2>
<p class="imgpreview"><a href="http://www.webia.info/wp-content/uploads/2009/11/form_labels_top.jpg"><img src="http://www.webia.info/wp-content/uploads/2009/11/form_labels_top.jpg" alt="Edward Pistachio contact form screenshot" /></a></p>
<p>
If the article just above tackled the practical part of web forms, this one tackles theoretical stuff and you should really read it because it contains a lot of tips, tricks, pros and cons on different web form styling patterns and more. Such a great article even Caroline Jarrett, author of the great book "<a href="http://www.formsthatwork.com/">Forms that work: Designing web forms for usability</a>", got her own tips in the comments section.
</p>
<h2>And there's more</h2>
<p>
The above articles are not everything we've got. Just check out our other articles, or stay updated to new content via our <a href="http://feeds2.feedburner.com/WebInternationalAwards" target="_new">RSS feed</a> or by <a href="http://feedburner.google.com/fb/a/mailverify?uri=WebInternationalAwards&#038;loc=en_US" target="_new">email</a>.
</p>]]></content:encoded>
			<wfw:commentRss>http://www.webia.info/misc/best-of-the-best/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building a live news blogging system in php. Spiced with HTML5, CSS3 and jQuery [part V]</title>
		<link>http://www.webia.info/articles/tutorials/building-a-live-news-blogging-system-in-php-spiced-with-html5-css3-and-jquery-part-v/</link>
		<comments>http://www.webia.info/articles/tutorials/building-a-live-news-blogging-system-in-php-spiced-with-html5-css3-and-jquery-part-v/#comments</comments>
		<pubDate>Tue, 11 May 2010 08:00:51 +0000</pubDate>
		<dc:creator>Bogdan Pop</dc:creator>
				<category><![CDATA[tutorials]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[live news system]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.webia.info/?p=1616</guid>
		<description><![CDATA[

About a month ago I started a series of tutorials on building a live blogging system in php. In case you missed it, you should definitely start with the first part of the series, or at least check out the demo.


Until now I've covered building the database, login functionalities for administrators, adding and deleting news [...]]]></description>
			<content:encoded><![CDATA[<p class="imgpreview"><a href="http://www.webia.info/wp-content/uploads/2010/03/lns_preview_full.jpg" title="Tutorial app preview"><img src="http://www.webia.info/wp-content/uploads/2010/03/lnw_preview.jpg" alt="Tutorial app preview" /></a></p>
<p>
About a month ago I started a series of tutorials on building a live blogging system in php. In case you missed it, you should definitely start with the <a href="http://www.webia.info/articles/tutorials/building-a-live-news-blogging-system-in-php-spiced-with-html5-css3-and-jquery-part-i/" target="_self">first part</a> of the series, or at least check out the <a href="http://www.webia.info/articles/tutorials/building-a-live-news-blogging-system-in-php-spiced-with-html5-css3-and-jquery-demo/" target="_self">demo</a>.
</p>
<p>
Until now I've covered building the database, login functionalities for administrators, adding and deleting news from the database. Today I'll cover editing existing news. 
</p>
<h2>The edit form</h2>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;div class=&quot;editform hidden&quot;&gt;
	&lt;form action=&quot;editnews.php&quot; method=&quot;post&quot; accept-charset=&quot;utf-8&quot; id=&quot;form-overlay&quot; class=&quot;insertcontent&quot;&gt;
		&lt;fieldset&gt;
&nbsp;
			&lt;label for=&quot;edittitle&quot;&gt;Title : &lt;/label&gt;
			&lt;input type=&quot;text&quot; name=&quot;edittitle&quot; value=&quot;&quot; id=&quot;edittitle&quot; class=&quot;edittitle all-rounded&quot; /&gt;
			&lt;label for=&quot;editformcategory&quot;&gt;Category :&lt;/label&gt;
			&lt;select name=&quot;editformcategory&quot; id=&quot;editformcategory&quot; size=&quot;1&quot; class=&quot;editcategory&quot;&gt;
				&lt;option selected=&quot;selected&quot; value=&quot;Economics&quot;&gt;Economics&lt;/option&gt;&lt;option value=&quot;Education&quot;&gt;Education&lt;/option&gt;&lt;option value=&quot;Health&quot;&gt;Health&lt;/option&gt;&lt;option value=&quot;IT&quot;&gt;IT&lt;/option&gt;&lt;option value=&quot;Politics&quot;&gt;Politics&lt;/option&gt;&lt;option value=&quot;Weather&quot;&gt;Weather&lt;/option&gt;					&lt;/select&gt;
&nbsp;
			&lt;label for=&quot;editbody&quot;&gt;Body text :&lt;/label&gt;
			&lt;textarea name=&quot;editbody&quot; rows=&quot;8&quot; cols=&quot;40&quot; class=&quot;editbody all-rounded&quot;&gt;&lt;/textarea&gt;
			&lt;input type=&quot;hidden&quot; name=&quot;editid&quot; value=&quot;&quot; id=&quot;editid&quot; class=&quot;editid hidden&quot; /&gt;
			&lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Edit news&quot; id=&quot;submit&quot; class=&quot;submit all-rounded&quot; /&gt;
		&lt;/fieldset&gt;
	&lt;/form&gt;
&lt;/div&gt;</pre></td></tr></table></div>



<p>
I coded the edit form in the first article. However, this form needs be loaded with the proper content. If it shows up empty it isn't an edit form anymore. That's done by editing the html code and inserting some php snippets as follows.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">&lt;div class=&quot;editform hidden&quot;&gt;
	&lt;form action=&quot;editnews.php&quot; method=&quot;post&quot; accept-charset=&quot;utf-8&quot; id=&quot;form-overlay&quot; class=&quot;insertcontent&quot;&gt;
		&lt;fieldset&gt;
			&lt;label for=&quot;edittitle&quot;&gt;Title : &lt;/label&gt;
			&lt;input type=&quot;text&quot; name=&quot;edittitle&quot; value=&quot;&quot; id=&quot;edittitle&quot; class=&quot;edittitle all-rounded&quot; /&gt;
			&lt;label for=&quot;editformcategory&quot;&gt;Category :&lt;/label&gt;
			&lt;select name=&quot;editformcategory&quot; id=&quot;editformcategory&quot; size=&quot;1&quot; class=&quot;editcategory&quot;&gt;
				<span style="color: #000000; font-weight: bold;">&lt;?</span> list_categories<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;select-options&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
			&lt;/select&gt;
			&lt;label for=&quot;editbody&quot;&gt;Body text :&lt;/label&gt;
			&lt;textarea name=&quot;editbody&quot; rows=&quot;8&quot; cols=&quot;40&quot; class=&quot;editbody all-rounded&quot;&gt;&lt;/textarea&gt;
			&lt;input type=&quot;hidden&quot; name=&quot;editid&quot; value=&quot;&quot; id=&quot;editid&quot; class=&quot;editid hidden&quot; /&gt;
			&lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Edit news&quot; id=&quot;submit&quot; class=&quot;submit all-rounded&quot; /&gt;
		&lt;/fieldset&gt;
	&lt;/form&gt;
&lt;/div&gt;</pre></td></tr></table></div>



<p>
The only part that's changed from the raw html form is the code inside the <em>select</em> tag. I've started coding that function and presented it in the <a href="http://www.webia.info/articles/tutorials/building-a-live-news-blogging-system-in-php-spiced-with-html5-css3-and-jquery-part-iii/" target="_self">third part</a> of the tutorial.
</p>
<p>
However, only with the php code above, I've fixed only the category issue. The rest of the form elements are still empty. Populating them with valid data is done via jQuery. Data is read directly from the DOM and appended accordingly into the form. I've started the overlay function in the <a href="http://www.webia.info/articles/tutorials/building-a-live-news-blogging-system-in-php-spiced-with-html5-css3-and-jquery-part-ii/" target="_self">second part</a> of the series, and now I am altering that function to add the required functionalities. Just after the 11th line (<em>var rel = $(this).attr('rel');</em>) in the overlay's function code we add the following:
</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>rel<span style="color: #339933;">==</span><span style="color: #3366CC;">'editform'</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> id <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'title'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">var</span> article <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>			
	<span style="color: #003366; font-weight: bold;">var</span> details <span style="color: #339933;">=</span> article.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'details'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> category <span style="color: #339933;">=</span> details.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'span.cat'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> body <span style="color: #339933;">=</span> article.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'p'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> title <span style="color: #339933;">=</span> article.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'h1'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> modal_content <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.'</span><span style="color: #339933;">+</span>rel<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#overlay-content div'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>modal_content<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'input.editid'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'input.edittitle'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>title<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'textarea.editbody'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span>body<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>



<p>
By adding the above code, when someone clicks the edit link of a news item, an overlay pops out displaying the contents of the news which are loaded from the DOM itself (directly from the <em>article</em> tags). Users can then edit the content and save it.
</p>
<h2>editnews.php</h2>
<p>
We need to somehow process the edit request and we do that with a script similar to the addnews.php file I talked about in <a href="http://www.webia.info/articles/tutorials/building-a-live-news-blogging-system-in-php-spiced-with-html5-css3-and-jquery-part-iii/" target="_self">part three</a> of the series.
</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>
<span style="color: #990000;">session_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;includes/functions.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">session_is_registered</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'logged in key'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$er</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'edittitle'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$er</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'1'</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">else</span> <span style="color: #000088;">$title</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'edittitle'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'editformcategory'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$er</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'1'</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">else</span> <span style="color: #000088;">$formcategory</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'editformcategory'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'editbody'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$er</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'1'</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">else</span> <span style="color: #000088;">$body</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'editbody'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'editid'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$er</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'1'</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">else</span> <span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'editid'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$er</span><span style="color: #339933;">==</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;location: index.php?error=Please input username and password&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">else</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$title</span> <span style="color: #339933;">=</span> strip_all<span style="color: #009900;">&#40;</span><span style="color: #000088;">$title</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$formcategory</span> <span style="color: #339933;">=</span> strip_all<span style="color: #009900;">&#40;</span><span style="color: #000088;">$formcategory</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$body</span> <span style="color: #339933;">=</span> strip_all<span style="color: #009900;">&#40;</span><span style="color: #000088;">$body</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$username</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;UPDATE News SET `body` = '<span style="color: #006699; font-weight: bold;">$body</span>', `title` = '<span style="color: #006699; font-weight: bold;">$title</span>', `category` = '<span style="color: #006699; font-weight: bold;">$formcategory</span>' WHERE `id`='<span style="color: #006699; font-weight: bold;">$id</span>';&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$query</span><span style="color: #339933;">;</span>
		<span style="color: #339933;">@</span><span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;location: index.php?msg=News edited successfully&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span> <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;location: index.php?error=You must be logged in to access this feature.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>



<p>
The above code first checks for administrator status, then form data input errors. If everything is in order the news is edited and changes saved to the database.
</p>
<p>If you enjoyed this article you can stay updated to new content via our <a href="http://feeds2.feedburner.com/WebInternationalAwards" target="_new">RSS feed</a> or by <a href="http://feedburner.google.com/fb/a/mailverify?uri=WebInternationalAwards&#038;loc=en_US" target="_new">email</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.webia.info/articles/tutorials/building-a-live-news-blogging-system-in-php-spiced-with-html5-css3-and-jquery-part-v/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
