<?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>Giladon-line &#187; code</title>
	<atom:link href="http://giladlotan.com/blog/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://giladlotan.com/blog</link>
	<description>culture technology: bridging the gap</description>
	<lastBuildDate>Tue, 18 May 2010 00:29:10 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>pagination using php, javascript and html</title>
		<link>http://giladlotan.com/blog/2009/03/pagination-using-php-javascript-and-html/</link>
		<comments>http://giladlotan.com/blog/2009/03/pagination-using-php-javascript-and-html/#comments</comments>
		<pubDate>Sat, 07 Mar 2009 07:23:58 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[pagination]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://giladlotan.com/blog/?p=401</guid>
		<description><![CDATA[<p style="text-align: left;">Earlier this week I set out to build a little webapp &#8211; essentially a visual, easy-to-use wrapper over a mySQL database which included a wide array of data. Naturally, I set to add pagination to the app, along with filtering functionality. Automatically, I set out to search the web for pre-written modules. I [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;">Earlier this week I set out to build a little webapp &#8211; essentially a visual, easy-to-use wrapper over a mySQL database which included a wide array of data. Naturally, I set to add pagination to the app, along with filtering functionality. Automatically, I set out to search the web for pre-written modules. I wasted several hours trying semi-documented solutions until I broke down and finally decided to just write it myself.</p>
<p style="text-align: left;">I must say, it was actually much more complex than I&#8217;d thought. When controling pagination of a site, especially with dynamic content being pulled from a database, the application constantly needs to figure out where in relation to the database results, the user is browsing, how many pages forward or backward exist, and all the end cases (first/last pages).</p>
<div class="mceTemp mceIEcenter" style="text-align: left;">
<dl id="attachment_403" class="wp-caption aligncenter" style="width: 409px;">
<dt class="wp-caption-dt"><a href="http://giladlotan.com/blog/wp-content/uploads/2009/03/dreamweaver-3.jpg"><img class="size-medium wp-image-403" title="pagination" src="http://giladlotan.com/blog/wp-content/uploads/2009/03/dreamweaver-3-300x30.jpg" alt="pagination" width="399" height="39" /></a></dt>
<dd class="wp-caption-dd">pagination example </dd>
</dl>
</div>
<p style="text-align: left;">In this example I used the jquery library to make the AJAX calls (no need to usually). The ajax call updates the #results div with the content. The .php file holds the majority of the functionality &#8211; calculates the number of pages (according to # of entries we want per page), then according to the current page, calculates how many before and after, creates the links, and makes sure the current page is not clickable.</p>
<p style="text-align: left;">Here are links to the files: (note &#8211; you need to insert your own database info in the php file for this to work)</p>
<p style="text-align: left;"><a href="http://giladlotan.com/code/pagination.html">pagination.html</a></p>
<p style="text-align: left;"><a href="http://giladlotan.com/code/pagination.php">pagination.php</a></p>
<p style="text-align: left;">And below is the .php code I created:</p>
<p style="text-align: left;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;&gt;&gt;</p>
<p style="text-align: left;">&lt;?php</p>
<p>$mysql = mysql_connect(&#8221;***your host***&#8221;,&#8221;***your username***&#8221;,&#8221;**your password***&#8221;) or die(mysql_error());<br />
mysql_select_db(&#8221;****your db****&#8221;,$mysql) or die(mysql_error());</p>
<p>$NUMPADDING=6; // number of links on either side of the current page</p>
<p>$pagenum = $_GET['pagenum'];<br />
$page_rows = $_GET['page_rows'];</p>
<p>$data = mysql_query(&#8221;SELECT * FROM entries&#8221;) or die(mysql_error());<br />
$rows = mysql_num_rows($data);</p>
<p>//This tells us the page number of our last page<br />
$last = ceil($rows/$page_rows);</p>
<p>// SQL QUERY<br />
//This sets the range to display in our query<br />
$max = &#8216;limit &#8216; .($pagenum &#8211; 1) * $page_rows .&#8217;,&#8217; .$page_rows;</p>
<p>//echo &#8220;SELECT * FROM entries $max&#8221;;</p>
<p>$data_p = mysql_query(&#8221;SELECT * FROM ***your tablename*** $max&#8221;) or die(mysql_error());</p>
<p>// FIRST<br />
echo&#8217;&lt;div id=&#8221;pagination&#8221;&gt;<br />
&lt;ul id=&#8221;pagination&#8221;&gt;<br />
&lt;li class=&#8221;first&#8221;&gt;&lt;a href=&#8221;javascript:getPage(\&#8217;1\&#8217;,\&#8221;.$page_rows.&#8217;\',\&#8217;this\&#8217;)&#8221;&gt;first&lt;/a&gt;&lt;/li&gt;&#8217;;</p>
<p>// PREV<br />
if ($pagenum&gt;1) {<br />
$prevpage=$pagenum-1;<br />
echo&#8217;&lt;li class=&#8221;previous&#8221;&gt;&lt;a href=&#8221;javascript:getPage(\&#8221;.$prevpage.&#8217;\',\&#8221;.$page_rows.&#8217;\',\&#8217;this\&#8217;)&#8221;&gt;&lt;- previous&lt;/a&gt;&lt;/li&gt;&#8217;;<br />
//echo&#8217;&#8230;&#8217;;<br />
// &#8212;PADDING</p>
<p>if ($pagenum-$NUMPADDING&gt;0)<br />
$start=$pagenum-$NUMPADDING;<br />
else<br />
$start=1;</p>
<p>for ($i=$start;$i&lt;$pagenum;$i++){<br />
$tmp=$i;<br />
echo&#8217;&lt;li&gt;&lt;a href=&#8221;javascript:getPage(\&#8221;.$tmp.&#8217;\',\&#8221;.$page_rows.&#8217;\',\&#8217;this\&#8217;)&#8221;&gt;&#8217;.$tmp.&#8217;&lt;/a&gt;&lt;/li&gt;&#8217;;<br />
}<br />
}<br />
else<br />
// no prev necessary<br />
echo&#8217;&lt;li class=&#8221;previous-off&#8221;&gt;&lt;- previous&lt;/li&gt;&#8217;;</p>
<p>// CURRENT PAGE<br />
echo&#8217;&lt;li class=&#8221;active&#8221;&gt;&#8217;.$pagenum.&#8217;&lt;/li&gt;&#8217;;</p>
<p>// NEXT<br />
if ($pagenum&lt;$last) {<br />
// PADDING+++<br />
if ($last-$pagenum &gt; $NUMPADDING)<br />
$end=$NUMPADDING;<br />
else<br />
$end=$last-$pagenum;</p>
<p>for ($i=1;$i&lt;=$end;$i++){<br />
$tmp=$pagenum+$i;<br />
echo&#8217;&lt;li&gt;&lt;a href=&#8221;javascript:getPage(\&#8221;.$tmp.&#8217;\',\&#8221;.$page_rows.&#8217;\',\&#8217;this\&#8217;)&#8221;&gt;&#8217;.$tmp.&#8217;&lt;/a&gt;&lt;/li&gt;&#8217;;<br />
}<br />
//echo&#8217;&#8230;&#8217;;<br />
$nextpage=$pagenum+1;<br />
echo&#8217;&lt;li class=&#8221;next&#8221;&gt;&lt;a href=&#8221;javascript:getPage(\&#8221;.$nextpage.&#8217;\',\&#8221;.$page_rows.&#8217;\',\&#8217;this\&#8217;)&#8221;&gt;next -&gt;&lt;/a&gt;&lt;/li&gt;&#8217;;<br />
}<br />
else<br />
// no prev necessary<br />
echo&#8217;&lt;li class=&#8221;next-off&#8221;&gt;next -&gt;&lt;/li&gt;&#8217;;</p>
<p>//LAST<br />
echo&#8217;<br />
&lt;li class=&#8221;last&#8221;&gt;&lt;a href=&#8221;javascript:getPage(\&#8221;.$last.&#8217;\',\&#8221;.$page_rows.&#8217;\',\&#8217;this\&#8217;)&#8221;&gt;last&lt;/a&gt;&lt;/li&gt;<br />
&lt;/ul&gt;&lt;br/&gt;<br />
&lt;/div&gt;<br />
&#8216;;<br />
?&gt;</p>
<p style="text-align: left;">
<p style="text-align: left;">
<p style="text-align: left;">[tags]pagination,javascript,js,php,jquery,html,tutorial,code,example[/tags]</p>
<p style="text-align: left;">
<p style="text-align: left;">
]]></content:encoded>
			<wfw:commentRss>http://giladlotan.com/blog/2009/03/pagination-using-php-javascript-and-html/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Making round DIVs</title>
		<link>http://giladlotan.com/blog/2008/09/making-rounded-divs/</link>
		<comments>http://giladlotan.com/blog/2008/09/making-rounded-divs/#comments</comments>
		<pubDate>Mon, 22 Sep 2008 21:52:27 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://giladlotan.com/blog/?p=387</guid>
		<description><![CDATA[<p>Here&#8217;s the image-based method I used to make rounded DIVs. Use the following HTML code along with the CSS properties and .gif files. The results are a lot of fun and look quite good:
</p>

<p>[tags]html,code,programming,round,div,css[/tags]</p>
]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s the image-based method I used to make rounded DIVs. Use the following <a href="http://giladlotan.com/code/rounddiv/">HTML code</a> along with the <a href="http://giladlotan.com/code/rounddiv/css/roundcorners.css">CSS properties</a> and <a href="http://giladlotan.com/code/rounddiv/css/imagesR/">.gif files.</a> The results are a lot of fun and look quite good:<br />
<a class="imagelink" title="div-rounded-corners-tutorial.jpg" href="http://giladlotan.com/code/rounddiv/" /></p>
<div style="text-align: center"><a class="imagelink" title="div-rounded-corners-tutorial.jpg" href="http://giladlotan.com/code/rounddiv/"><img id="image386" alt="div-rounded-corners-tutorial.jpg" src="http://giladlotan.com/blog/wp-content/uploads/2008/09/div-rounded-corners-tutorial.jpg" /></a></div>
<p>[tags]html,code,programming,round,div,css[/tags]</p>
]]></content:encoded>
			<wfw:commentRss>http://giladlotan.com/blog/2008/09/making-rounded-divs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>displaying Hebrew characters with PHP and MySQL</title>
		<link>http://giladlotan.com/blog/2008/01/displaying-hebrew-characters-with-php-and-mysql/</link>
		<comments>http://giladlotan.com/blog/2008/01/displaying-hebrew-characters-with-php-and-mysql/#comments</comments>
		<pubDate>Tue, 22 Jan 2008 13:03:06 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[israel]]></category>
		<category><![CDATA[news]]></category>

		<guid isPermaLink="false">http://giladlotan.com/blog/?p=270</guid>
		<description><![CDATA[<p>I&#8217;ve been working on a little application that grabs data from Hebrew news sites into a mySQL database.</p>

<p>While working on this mini-project I&#8217;ve realized that there is hardly any online tutorials on using the Hebrew font. Here&#8217;s my solution which is fairly simple and works effectively.</p>
<p>Step 1) Set the HTML page charset encoding to utf8:</p>
<p>meta [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on a little application that grabs data from Hebrew news sites into a mySQL database.</p>
<div style="text-align: center"><img id="image272" alt="hebrew-type.jpg" src="http://giladlotan.com/blog/wp-content/uploads/2008/01/hebrew-type.jpg" /></div>
<p>While working on this mini-project I&#8217;ve realized that there is hardly any online tutorials on using the Hebrew font. Here&#8217;s my solution which is fairly simple and works effectively.</p>
<p>Step 1) Set the HTML page charset encoding to utf8:</p>
<blockquote><p>meta http-equiv=&#8221;Content-Type&#8221; content=&#8221;text/html; <strong>charset=UTF-8</strong>&#8220;</p></blockquote>
<p>Step 2) set the &#8216;collation&#8217; attribute for the fields which are to accept hebrew text to: <strong>utf8_bin</strong></p>
<p>Step 3) within your php script, right before calling the mysql_query function to insert the data into your DB, use both the <strong>utf8_encode</strong> function along with <strong>addslashes</strong>. This will encode the data into utf8 friendly characters.</p>
<p>Step 4) when pulling the text from the DB onto the page, make sure to use the <strong>utf8_decode</strong> along with <strong>stripslashes </strong>in order to display the data on the page.</p>
<p>Here&#8217;s a <a href="http://giladlotan.com/news/hebrew.php">link</a> to an example page which displays the latest story (title +  short description) from the ma&#8217;ariv news site. The full code is <a href="http://giladlotan.com/news/talkback.txt">here</a> (remember to insert your own database name and password). The code parses the ma&#8217;ariv news rss feed using the following <a href="http://apptools.com/phptools/downloads/rssreader.zip">rssreader.php</a> wrapper, inserts the newest articles into a mySQL database (if the article does not already exist in the db), and then queries the database for the most recent post, and displays the information on the HTML page.</p>
<p>[tags] hebrew, php, programming, code, utf8, mysql [/tags]</p>
]]></content:encoded>
			<wfw:commentRss>http://giladlotan.com/blog/2008/01/displaying-hebrew-characters-with-php-and-mysql/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
