<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>comicbookUPCdb.com</title>
	
	<link>http://comicbookupcdb.com/blog</link>
	<description>Get Comic Book info by entering its UPC code</description>
	<lastBuildDate>Wed, 02 Mar 2011 18:33:19 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language />
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/ComicBookUPCdb" /><feedburner:info uri="comicbookupcdb" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>New Logo for web site</title>
		<link>http://feedproxy.google.com/~r/ComicBookUPCdb/~3/DhiHW70RLOs/new-logo-for-web-site</link>
		<comments>http://comicbookupcdb.com/blog/new-logo-for-web-site#comments</comments>
		<pubDate>Wed, 02 Mar 2011 18:33:19 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://comicbookupcdb.com/blog/?p=206</guid>
		<description><![CDATA[Also durring my hiatus, and thanks to the good folks at MacUpdate, I got a copy of Art Text (a very cool program for making logos, buttons and styled text) and came up with a new logo for the web site.

For the main font I used Comic Craft Slap Happy Open which I got a [...]]]></description>
			<content:encoded><![CDATA[<p>Also durring my hiatus, and thanks to the good folks at <a href="http://www.mupromo.com/" target="_blank">MacUpdate</a>, I got a copy of <a href="http://www.macupdate.com/app/mac/23541/art-text" target="_blank">Art Text</a> (a very cool program for making logos, buttons and styled text) and came up with a new logo for the web site.</p>
<p><a href="http://comicbookupcdb.com/blog/wp-content/uploads/2011/03/CBUDB-Logo-100T.jpg" rel="lightbox[206]"><img class="alignnone size-full wp-image-209" title="CBUDB-Logo-100T" src="http://comicbookupcdb.com/blog/wp-content/uploads/2011/03/CBUDB-Logo-100T.jpg" alt="CBUDB-Logo-100T" width="331" height="100" /></a></p>
<p>For the main font I used <a title="Purchase Slap Happy $60" href="http://www.comicbookfonts.com/fonts/catalog.html?item=fonts:fx132i&amp;sid=0001GatzDocRxdgmU00c427" target="_blank">Comic Craft Slap Happy Open</a> which I got a great deal on (along with some other Comic Craft fonts including <a href="http://www.comicbookfonts.com/fonts/catalog.html?item=fonts:bl001&amp;sid=0001iMXTjqv2c5IwPY5U4y5" target="_blank">ComiCrazy</a> regularly $395, got it for $20.10) on during their <a href="http://ihnatko.com/2008/01/01/bargain-font-day-bargain-font-day-bargain-font-day-act-now/" target="_blank">New Year&#8217;s sale which Andy Ihnatko tipped me off to</a>.</p>
<img src="http://feeds.feedburner.com/~r/ComicBookUPCdb/~4/DhiHW70RLOs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://comicbookupcdb.com/blog/new-logo-for-web-site/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://comicbookupcdb.com/blog/new-logo-for-web-site</feedburner:origLink></item>
		<item>
		<title>New Progress</title>
		<link>http://feedproxy.google.com/~r/ComicBookUPCdb/~3/l0dt_ACk7uw/new-progress</link>
		<comments>http://comicbookupcdb.com/blog/new-progress#comments</comments>
		<pubDate>Wed, 02 Mar 2011 17:09:34 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://comicbookupcdb.com/blog/?p=203</guid>
		<description><![CDATA[Well its been a year since I last posted but suffice to say that there has been much going on in my life that has kept me from making forward progress on the application as originally as planned. The dog is better and his surgery will only delay our retirement by a year or so. [...]]]></description>
			<content:encoded><![CDATA[<p>Well its been a year since I last posted but suffice to say that there has been much going on in my life that has kept me from making forward progress on the application as originally as planned. The dog is better and his surgery will only delay our retirement by a year or so. Winter is here so I&#8217;ve actually have had a little more downtime to refocus on the effort&#8230;</p>
<p>Started a new effort recently that focuses more on the data entry aspect of database. The thought is, there isn&#8217;t much use in having a really great system to edit and maintain all the data without having a way to motivate people to enter it in the first place. The vehicle for having users enter data is an comic cataloging application that lets users track and view their collection. The basic idea of this new direction is to have a wizard type application that lets you index comics by the box (or partial box) for existing collections or by purchases as you buy comics (i.e., every Wednesday). You scan the comic&#8217;s UPC and if it exists in the database, it is added to your collection. If its not in the database the application prompts you add it with the focus on that you add the UPC of the comic book that you&#8217;re trying to index.</p>
<p>The application will have support for:</p>
<ul>
<li>Automatically obtaining cover images or allowing the user to upload them</li>
<li>Ability to upload a scan of the comic&#8217;s <a title="What is an indicia" href="http://en.wikipedia.org/wiki/Indicia_(publishing)" target="_blank">indicia</a></li>
<li>Pull List &amp; Purchase tracking / management to allow the automated entry of comics purchased from dealers with a fixed discount off a cover price</li>
<li>Box / Location management to allow you to see where your comics are and how to reorganize them based on box capacity and the number of issues of a give tittle that you own.</li>
</ul>
<p>I don&#8217;t want to go into too much detail other than its coming along&#8230; I will post more updates soon.</p>
<img src="http://feeds.feedburner.com/~r/ComicBookUPCdb/~4/l0dt_ACk7uw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://comicbookupcdb.com/blog/new-progress/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://comicbookupcdb.com/blog/new-progress</feedburner:origLink></item>
		<item>
		<title>Delayed</title>
		<link>http://feedproxy.google.com/~r/ComicBookUPCdb/~3/QRS9qpWQoDY/delayed</link>
		<comments>http://comicbookupcdb.com/blog/delayed#comments</comments>
		<pubDate>Mon, 03 May 2010 20:37:32 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://comicbookupcdb.com/blog/?p=196</guid>
		<description><![CDATA[Just wanted to post something on the blog here about the lack of recent activity&#8230; We&#8217;ve recently have brought home a new puppy. Not only is he quite fun, but he&#8217;s also a handful!
As such I haven&#8217;t had a whole lot of time at night to work on anything for the web site. Not only [...]]]></description>
			<content:encoded><![CDATA[<p>Just wanted to post something on the blog here about the lack of recent activity&#8230; We&#8217;ve recently have brought home a new puppy. Not only is he quite fun, but he&#8217;s also a handful!</p>
<p>As such I haven&#8217;t had a whole lot of time at night to work on anything for the web site. Not only no time, but since the puppy is getting me up at least once during the night and up at 7:00 AM every day (no sleeping in on Saturdays and Sundays) I&#8217;m really tired all the time.</p>
<p>Here&#8217;s the little dickens&#8230;</p>
<p><a href="http://comicbookupcdb.com/blog/wp-content/uploads/2010/05/Theo-015.jpg" rel="lightbox[196]"><img class="alignnone size-medium wp-image-200" title="Theo 015" src="http://comicbookupcdb.com/blog/wp-content/uploads/2010/05/Theo-015-300x225.jpg" alt="Theo 015" width="300" height="225" /></a></p>
<p><a href="http://comicbookupcdb.com/blog/wp-content/uploads/2010/05/Theo-019.jpg" rel="lightbox[196]"><img class="alignnone size-medium wp-image-198" title="Theo 019" src="http://comicbookupcdb.com/blog/wp-content/uploads/2010/05/Theo-019-225x300.jpg" alt="Theo 019" width="225" height="300" /></a></p>
<p><a href="http://comicbookupcdb.com/blog/wp-content/uploads/2010/05/Theo-018.jpg" rel="lightbox[196]"><img class="alignnone size-medium wp-image-199" title="Theo 018" src="http://comicbookupcdb.com/blog/wp-content/uploads/2010/05/Theo-018-225x300.jpg" alt="Theo 018" width="225" height="300" /></a></p>
<img src="http://feeds.feedburner.com/~r/ComicBookUPCdb/~4/QRS9qpWQoDY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://comicbookupcdb.com/blog/delayed/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://comicbookupcdb.com/blog/delayed</feedburner:origLink></item>
		<item>
		<title>How to determine the Record Offset given a primary key and a defined order by clause – Part 3</title>
		<link>http://feedproxy.google.com/~r/ComicBookUPCdb/~3/t8VdmejNGCo/how-to-determine-the-record-offset-given-a-primary-key-and-a-defined-order-by-clause-%e2%80%93-part-3</link>
		<comments>http://comicbookupcdb.com/blog/how-to-determine-the-record-offset-given-a-primary-key-and-a-defined-order-by-clause-%e2%80%93-part-3#comments</comments>
		<pubDate>Sat, 17 Apr 2010 16:25:29 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://comicbookupcdb.com/blog/?p=189</guid>
		<description><![CDATA[Part 3
See Parts 1 &#38; 2 of this article How to determine the Record Offset given a primary key and a defined order by clause &#8211; Part 1 and How to determine the Record Offset given a primary key and a defined order by clause &#8211; Part 2
Work in progress&#8230; check back soon.
]]></description>
			<content:encoded><![CDATA[<h1>Part 3</h1>
<p>See Parts 1 &amp; 2 of this article <a title="Part 1" href="http://comicbookupcdb.com/blog/how-to-determine-the-record-offset-given-a-primary-key-and-a-defined-order-by-clause-part-1" target="_self">How to determine the Record Offset given a primary key and a defined order by clause &#8211; Part 1</a> and <a title="Part 2" href="http://comicbookupcdb.com/blog/how-to-determine-the-record-offset-given-a-primary-key-and-a-defined-order-by-clause-part-2" target="_self">How to determine the Record Offset given a primary key and a defined order by clause &#8211; Part 2</a></p>
<p>Work in progress&#8230; check back soon.</p>
<img src="http://feeds.feedburner.com/~r/ComicBookUPCdb/~4/t8VdmejNGCo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://comicbookupcdb.com/blog/how-to-determine-the-record-offset-given-a-primary-key-and-a-defined-order-by-clause-%e2%80%93-part-3/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://comicbookupcdb.com/blog/how-to-determine-the-record-offset-given-a-primary-key-and-a-defined-order-by-clause-%e2%80%93-part-3</feedburner:origLink></item>
		<item>
		<title>Dev Sneak Peek vers 1.2.5</title>
		<link>http://feedproxy.google.com/~r/ComicBookUPCdb/~3/4VFTqpGjp34/dev-sneak-peek-vers-1-2-5</link>
		<comments>http://comicbookupcdb.com/blog/dev-sneak-peek-vers-1-2-5#comments</comments>
		<pubDate>Sat, 17 Apr 2010 15:22:21 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://comicbookupcdb.com/blog/?p=148</guid>
		<description><![CDATA[I just updated the Dev Sneak Peak from version 1.2 to 1.2.5. While not a significant jump in version number, the one major feature, Permalinks, was very complicated to implement. A Permalink, is a link that takes you back to a specific piece of content on a web site&#8230; for instance on a blogging web [...]]]></description>
			<content:encoded><![CDATA[<p>I just updated the <a title="Dev Sneak Peak Version 1.2.5 - with Permalinks" href="http://dev.comicbookupcdb.com/appl.php" target="_blank">Dev Sneak Peak</a> from version 1.2 to 1.2.5. While not a significant jump in version number, the one major feature, Permalinks, was very complicated to implement. A Permalink, is a link that takes you back to a specific piece of content on a web site&#8230; for instance on a blogging web site a Permalink would take you to a specific blog post. So a Permalink to the Comic Book UPC db maintenance tool would take you to a specific series and issue.</p>
<div id="attachment_158" class="wp-caption aligncenter" style="width: 649px"><a href="http://comicbookupcdb.com/blog/wp-content/uploads/2010/04/permalink.png" rel="lightbox[148]"><img class="size-full wp-image-158 " title="Permalink" src="http://comicbookupcdb.com/blog/wp-content/uploads/2010/04/permalink.png" alt="Permalink Button" width="639" height="108" /></a><p class="wp-caption-text">Permalink Button</p></div>
<p>This gets a little technical so you might want to skip the rest of this post and just try out the functionality (see next paragraph below). I also have included a follow up blog post about the <a title="How to calculate the record offset of a record using its primary key id" href="http://comicbookupcdb.com/blog/calculating-the-record-offset-given-its-primary-key" target="_blank">how to calculate the record offset</a> and the SQL used to implement it.</p>
<p>For example to go to issue 100 of the Fantastic Four (I created this Permalink after having searched the series by a publisher of Marvel and a series title starting with Fanta, and having filtered the list of issues so that only regular [i.e., not annuals or trade paper back book, etc.] are displayed, and having sorted the issues by UPC code in descending order) click on the following link&#8230; Yes I know its long, but all the &#8216;gook&#8217; after the appl.php part of the URL is the application&#8217;s state at the time the Permalink was created (i.e., the data to get you back to where you were when you created the Permalink).</p>
<p><a title="Fantastic Four 100 Permalink" href="http://dev.comicbookupcdb.com/appl.php?pubId=5&amp;srchOpNdx=1&amp;srchVal=fanta&amp;fltrFldNdx=0&amp;fltrOpNdx=0&amp;fltrVal=37&amp;serSortFld=name&amp;serSortDir=ASC&amp;serId=5427&amp;issSortFld=upc&amp;issSortDir=DESC&amp;varId=74043" target="_blank">http://dev.comicbookupcdb.com/appl.php?pubId=5&amp;srchOpNdx=1&amp;srchVal=fanta&amp;fltrFldNdx=0&amp;fltrOpNdx=0&amp;fltrVal=37&amp;serSortFld=name&amp;serSortDir=ASC&amp;serId=5427&amp;issSortFld=upc&amp;issSortDir=DESC&amp;varId=74043</a></p>
<p>While simple in concept, the complication in implementing Permalinks arises because the Comic Book UPC db web site is an AJAX based web application and that it uses paged record sets, that and the fact that the data is/will be constantly changing. In implementing the Permalink functionality I wanted to be able to restore the applications state (what publisher, series title, issue filter, etc. that the user had used) to exactly what the user had when they generated the Permalink.</p>
<p>But the real difficulty arose when trying to calculate the record offsets for the series and issue the user had selected. FYI, the record offset is used by the applications paging logic to determine which page of the data to display. For example, if the user had selected the 10th issue on 3rd page and there are 25 records on a page, the record offset for the selected issue would be 25 x 3 + 10 &#8211; 1 = 84 (offset values start at 0, hence the minus 1).</p>
<p>Knowing the record offset then allows us to calculate the starting offset for the page containing the selected issue. To do with we would first calculate the offset of the selected issue from the start of the page, this is simply the offset modulo the number of records per page (the modulo operator is the remainder of X divided by Y, e.g., 43 divided by 20 is 2 reminder 3, so 43 modulo 20 is 3). So in our example that would be 84 modulo 25 is 9. The starting offset for the page is then the offset minus the offset of the selected from the start of the page, in this case 84 -9 = 75 (this makes sense as we were on the 3rd page and there are 25 records per page).</p>
<p>The application then uses the page starting offset of 75, to display the 3rd page of data and the offset of the selected issue from the start of the page of 9 to select the 10th (counting starting from 0) issue on the 3rd page. Thus selecting the same record the user had selected when they created the Permalink.</p>
<p>So you say, whats so difficult about that, just have the application store the starting offset for the page and the record offset from the beginning of the page in the Permalink, as it surely knows this information at the time the user creates the Permalink. Ah, but the data in the application is constantly changing, new records are continually being added and deleted in the database. So the number of issues that come before the selected issue could change from the time the user creates the Permalink and when they return to the web site by clicking the Permalink. That and the fact that depending on how the user has the list of issues sorted also changes where it appears in the list of issues. For example if the user has issue 10 of the Fantastic Four selected and there are 200 issues for this series (assuming consecutive issues) if he has sorted by issue number in ascending sequence, then he has the 10th record (offset of 9) selected on the first page (assuming 25 records per page). But if he has sorted by issue number in descending order and has issue number 10 selected, its offset is 189, its offset from the start of the page is 14 and the page starting offset is 175!</p>
<p>This is probably making you head spin, as it did mine when I first tried to implement Permalinks. The simple solution would have been when the user clicks the Permalink, to issue an SQL select statement using the sort order that the user had specified (previously when they created the Permalink) and retrieve all the records less than the record previously selected. The process would then be to iterate through the records returned, incrementing a counter for each record.</p>
<p>But that would mean if the user had selected the 173,301 record in the list, that we&#8217;d have to loop through 173,300 records and count them!! To see the technical solution and SQL continue reading <a title="How to calculate the record offset of a record using its primary key id" href="http://comicbookupcdb.com/blog/calculating-the-record-offset-given-its-primary-key" target="_blank">this blog post</a>.</p>
<img src="http://feeds.feedburner.com/~r/ComicBookUPCdb/~4/4VFTqpGjp34" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://comicbookupcdb.com/blog/dev-sneak-peek-vers-1-2-5/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://comicbookupcdb.com/blog/dev-sneak-peek-vers-1-2-5</feedburner:origLink></item>
		<item>
		<title>How to determine the Record Offset given a primary key and a defined order by clause – Part 2</title>
		<link>http://feedproxy.google.com/~r/ComicBookUPCdb/~3/lkfC0LDmCi0/how-to-determine-the-record-offset-given-a-primary-key-and-a-defined-order-by-clause-part-2</link>
		<comments>http://comicbookupcdb.com/blog/how-to-determine-the-record-offset-given-a-primary-key-and-a-defined-order-by-clause-part-2#comments</comments>
		<pubDate>Fri, 16 Apr 2010 20:24:07 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://comicbookupcdb.com/blog/?p=166</guid>
		<description><![CDATA[Part 2
See Part 1 of this article How to determine the Record Offset given a primary key and a defined order by clause &#8211; Part 1
To summarize where we left off in part 1, our user sorted our table by age descending and selected 16th record on the 5th page (25 records per page). The [...]]]></description>
			<content:encoded><![CDATA[<h1>Part 2</h1>
<p>See Part 1 of this article <a title="Part 1" href="http://comicbookupcdb.com/blog/how-to-determine-the-record-offset-given-a-primary-key-and-a-defined-order-by-clause-part-1" target="_self">How to determine the Record Offset given a primary key and a defined order by clause &#8211; Part 1</a></p>
<p>To summarize where we left off in part 1, our user sorted our table by age descending and selected 16th record on the 5th page (25 records per page). The record has on offset of 140. The user book marks the record. 150 records are added (100 of them with an age less than 35) and 50 records are deleted (30 of them with an age less than 35). For a net change of 70 records with an age less than 35, resulting in a offset of 210.</p>
<p>So the question is how do we NOW determine the offset of the record that was book marked ONE week ago after the table has been updated?</p>
<p>One way we could do this is to execute the query again with the same sort and then loop through the records, counting them until we find the record with the primary key id the user book marked. Here&#8217;s our user&#8217;s book mark URL</p>
<p>http://www.example.com/pagedgui.php?id=48&amp;sort1=age&amp;dir1=desc</p>
<pre>$pk_id = $_GET['id']
$sort = $_GET['sort1'] . ' ' . $_GET['dir1']
$sql = 'select * from students order by ' . $sort
mysql_execute_query($sql);

$offset = 0
for each record
    if the primary key id of the current record == $pk_id then
        exit for
    end if
    $offset++
end for each</pre>
<p>When the loop exits $offset will have the offset of the record we&#8217;re looking for. Its kind of inefficient, but its simple and straight forward to implement. But what if you have a table with 300K plus records? And what if you have lots of users all accessing the web site at the same time? This probably isn&#8217;t the best solution.</p>
<p>Wait a minute! Doesn&#8217;t SQL have a count(*) function, can&#8217;t we use that? Yes and No. Yes we could use it, but not without doing some extra work as the only thing we have is the primary key id of the book marked record. So this would require us to lookup the value of the age of the record tat was book marked.</p>
<pre>$pk_id = $_GET['id']
$sort = $_GET['sort1'] . ' ' . $_GET['dir1']
$sql = 'select age from students where id = ' . $pk_id
mysql_execute_query($sql);

// returns a value of 35, see the previous post
$age = age of the record returned

// count all records with an age greater than 35 (descending sort here)
$sql = 'select count(*) as rec_count from students where age &lt; ' . $age .
    ' order by ' . $sort
mysql_execute_query($sql);
$offset = rec_count of the record return</pre>
<p>This certainly is an improvement in efficiency over the previous solution. But what if there are several records in the table with the age of 35, this will exclude more than just the record with the primary key id of 48. But what if we make it &gt;= (greater than or equal)? That wont work either for it may include some records that shouldn&#8217;t be included&#8230; in fact, we need a secondary sort, perhaps name.</p>
<pre>select count(*) as rec_count from students where age &gt;= $age and name &gt;= $name
order by age desc, name desc</pre>
<p>Ok, but what if there are two people with the same name and the same age? We have to add the primary key to the sort as well. In fact to make the above query work the primary key always has to be included in the sort to ensure that there is a guaranteed unique order.</p>
<pre>select count(*) as rec_count from students where age &gt;= $age and name &gt;= $name
and id &gt; $pk_id order by age desc, name desc, id desc</pre>
<p>That works (note: no two records can have the same primary key id, as it must be unique), but what if some one enters a record into the table that doesn&#8217;t have a age? NULL values are a fact that we have to deal with. So how about&#8230;</p>
<pre>select count(*) as rec_count from students where
(age is not null and $age is not null and age &gt;= $age) or
(age is not null and $age is null)
order by age desc</pre>
<p>Since NULL values sort after non Null values in a descending sort (at least in MySQL and before non NULL values in an ascending sort) if the age of the record being compared to is not null and the age of the record for the primary key pass in is NULL, then include the record in the count. We&#8217;ve also had to add not null clauses to the &gt;= comparison too. And I&#8217;ve also simplified this first pass at the query so you can see whats going on. If we were to also add in similar logic for the name field and add back in the final check for the primary key id, things really start to get messy quick.</p>
<pre>select count(*) as rec_count from students where
(age is not null and $age is not null and age &gt; $age) or
(age is not null and $age is not null and age = $age and name is not null
    and $name is not null and name &gt; $name) or
(age is not null and $age is not null and age = $age and name is not null
    and $name is not null and name = $name and id &gt; $pk_id) or
(age is not null and $age is null) or
(age is null and $age is null and name is not null and $name is not null
    and name &gt; $name) or
(age is null and $age is null and name is not null and $name is not null
    and name = $name and id &gt; $pk_id) or
(age is null and $age is null and name is not null and $name is null) or
(age is null and $age is null and name is null and $name is null
    and id &gt; $pk_id)
order by age desc, name desc, id desc</pre>
<p>YUCK! We can simplify this a little as follows&#8230;</p>
<pre>select count(*) as rec_count from students where
(age is not null and ($age is not null and age &gt; $age or
(name is not null and $name is not null and ((name &gt; $name) or
(name = $name and id &gt; $pk_id))))) or
($age is null and (age is not null or
(age is null and (($name is not null and name is not null and ((name &gt; $name) or
(name = $name and id &gt; $pk_id))) or ($name is null and ((name is not null) or
(name is null and id &gt; $pk_id)))))))
order by age desc, name desc, id desc</pre>
<p>But its no great improvement as it is on the complex side and this is only for 2 sort fields and the primary key!! Can you imagine what the SQL statement would look like for 7 or 8 sort fields? And what are the chances you could write the SQL statement without making any errors? There must be a better way&#8230;</p>
<p>See my next post, <a title="Part 3" href="http://comicbookupcdb.com/blog/how-to-determine-the-record-offset-given-a-primary-key-and-a-defined-order-by-clause-–-part-3" target="_self">How to determine the Record Offset given a primary key and a defined order by clause – Part 3</a>, for the answer.</p>
<img src="http://feeds.feedburner.com/~r/ComicBookUPCdb/~4/lkfC0LDmCi0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://comicbookupcdb.com/blog/how-to-determine-the-record-offset-given-a-primary-key-and-a-defined-order-by-clause-part-2/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://comicbookupcdb.com/blog/how-to-determine-the-record-offset-given-a-primary-key-and-a-defined-order-by-clause-part-2</feedburner:origLink></item>
		<item>
		<title>How to determine the Record Offset given a primary key and a defined order by clause – Part 1</title>
		<link>http://feedproxy.google.com/~r/ComicBookUPCdb/~3/yqzx8iTeHuY/how-to-determine-the-record-offset-given-a-primary-key-and-a-defined-order-by-clause-part-1</link>
		<comments>http://comicbookupcdb.com/blog/how-to-determine-the-record-offset-given-a-primary-key-and-a-defined-order-by-clause-part-1#comments</comments>
		<pubDate>Thu, 15 Apr 2010 15:17:51 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://comicbookupcdb.com/blog/?p=152</guid>
		<description><![CDATA[Part 1
For a little background on my issue and why I developed this solution see my previous post on Permalinks.
The problem:
I have a SQL SELECT statement with ORDER BY, OFFSET and LIMIT clauses. I take the result of the query and use it to present a paged record set via a GUI. After the users [...]]]></description>
			<content:encoded><![CDATA[<h1>Part 1</h1>
<p>For a little background on my issue and why I developed this solution see my previous post on <a title="Permalinks and use of record offset" href="http://comicbookupcdb.com/blog/dev-sneak-peek-vers-1-2-5" target="_blank">Permalinks</a>.</p>
<p>The problem:</p>
<p>I have a SQL SELECT statement with ORDER BY, OFFSET and LIMIT clauses. I take the result of the query and use it to present a paged record set via a GUI. After the users pages through the records (i.e., by clicking the GUI&#8217;s next page button to get the next set of records in the record set) and gets to the page that contains the record they are interested in, they can then select that record and &#8220;book mark&#8221; it. What I mean by &#8220;book mark&#8221; is they click a button and a static URL is generated so that they can later return to the URL and be right back at the same record. Additionally, the user can sort the records any way they want to, i.e., by filed A ascending or by field A descending and field B ascending or by field C ascending, field D descending, field A ascending and field B Descending, etc. Various filters can be applied to the record set in WHERE clause of the query as well.</p>
<p>The Solution:</p>
<p>When the user returns to the static URL presented above, the program needs to determine the offset of the previously selected record in the record set (as identified by its primary key ID in the static URL) when the same sort defined by the user (also in the static URL) is applied to the query. This will then allow us to determine 1) the offset of the first record on the same page as the selected record and 2) to determine the offset relative to the first record on the page. This needs to be done at the time the user returns to the static URL as additional records may be added to the record set or records may be deleted from the record set, i.e., there is no way to determine the offset of the selected record ahead of time because the number of records in the data set is dynamic and constantly changing. An example may help clarify things a bit.</p>
<p>Lets say on day 1 there are 300 records in our table and we display 25 records a page for a total of 12 pages. The offset of the first record on the first page would be 0 and the offset of the last record on the first page would be 24. The next page the first record would have an offset of 25, the last record, 49 and so on. Additionally besides the primary key, ID, our table has a name field and a age field.</p>
<p>Our user sorts the record set by the age field in descending order, navigates to the 5th page, selects the 16th record from the top and &#8220;book marks&#8221; it. The offset of the first record on the page is 25 x 5 &#8211; 1 = 124, the offset of the selected record is 25 X 5 + 16 &#8211; 1 = 140 and its offset from the top of the page is 140 modulo 25 = 15. This record has a primary key ID of 48, a name of Fred and an age of 35. The book marked static URL would contain the primary key id, the field(s) the user sorted the record set by and the direction of the sort (ascending or descending). The URL may look something like this:</p>
<p>http://www.example.com/pagedgui.php?id=48&amp;sort1=age&amp;dir1=desc</p>
<p>In the week that follows 150 records are added to the table and 50 records are deleted, for a total of 400 records (or 16 pages). 100 records with an age less than 35 were added, 30 records with an age less than 35 were deleted, with the remainder of the records added and deleted having an age greater than 35. The net results that when sorted by age, the record with a primary key id of 48 will now have an offset of 210 (140 + 100 &#8211; 30). It will now have an offset from the top of the page of 10 (the 11th record on the page&#8230; 210 modulo 25) and the first record on the page will have an offset of 200 (210 &#8211; 10 or 210 divided by 25 is 8 with a remainder of 10, then 8 x 25 = 200).</p>
<p>The following week our user returns by clicking on the URL. The real question is how do we NOW determine the offset of the record that he book marked ONE week ago?</p>
<p>For one possible solution see this post for <a title="Determine selected record offset for any ORDER BY sequence" href="http://www.tek-tips.com/faqs.cfm?fid=6615" target="_blank">Determine selected record offset for any ORDER BY sequence</a>.</p>
<p>Or continue reading with <a title="Part 2" href="http://comicbookupcdb.com/blog/how-to-determine-the-record-offset-given-a-primary-key-and-a-defined-order-by-clause-part-2" target="_self">How to determine the Record Offset given a primary key and a defined order by clause &#8211; Part 2</a></p>
<img src="http://feeds.feedburner.com/~r/ComicBookUPCdb/~4/yqzx8iTeHuY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://comicbookupcdb.com/blog/how-to-determine-the-record-offset-given-a-primary-key-and-a-defined-order-by-clause-part-1/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://comicbookupcdb.com/blog/how-to-determine-the-record-offset-given-a-primary-key-and-a-defined-order-by-clause-part-1</feedburner:origLink></item>
		<item>
		<title>DSP 1.2 Release Notes</title>
		<link>http://feedproxy.google.com/~r/ComicBookUPCdb/~3/AusY1iI7H20/dsp-1-2-release-notes</link>
		<comments>http://comicbookupcdb.com/blog/dsp-1-2-release-notes#comments</comments>
		<pubDate>Fri, 19 Mar 2010 03:14:51 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://comicbookupcdb.com/blog/?p=145</guid>
		<description><![CDATA[For release 1.2 of DSP (as I&#8217;ve been fondly calling the Developer Sneak Peak) here are the enhancements that were made:

Went  from a partial screen panel to a full screen view port to maximize the amount of real estate available for the application
added additional issue detail panel on the bottom to view the details on [...]]]></description>
			<content:encoded><![CDATA[<div>For release 1.2 of DSP (as I&#8217;ve been fondly calling the Developer Sneak Peak) here are the enhancements that were made:</div>
<ol>
<li>Went  from a partial screen panel to a full screen view port to maximize the amount of real estate available for the application</li>
<li>added additional issue detail panel on the bottom to view the details on the selected issue. This brings the number of panels up to 4
<ol>
<li>the series panel on the left &#8211; this is where your series search results are displayed. Select one to see available issues.</li>
<li>the series details panel on the upper right &#8211; this is where additional information about the series is displayed, such as notes about the series any information on continuity, etc.</li>
<li>the issues panel on the center right &#8211; this is where the available issues for a given series are display. Select one to see additional info on it in the issue detail panel or to edit it.</li>
<li>the issue details panel on the lower right &#8211; this is where additional information is displayed for the selected issue, such as notes on the issue, description on the variation, continuity information, cover thumbnail, etc.</li>
</ol>
</li>
<li>made all panels except for the issues panel collapsible. this means you can easily focus on the panel you&#8217;re dealing with and maximize its space</li>
<li>Added the capability to filter issues by any one field, for example, only show the Annual issue for a given series. Or show all issues that have variants for a given series.</li>
<li>Enhancements to the issues panel.
<ol>
<li>Added new notes column that show any notes for the selected issue as well as any description for the particular variant.</li>
<li>Added an Expand Notes button so that Notes column can be expanded or collapsed vertically to see all of the issue notes and/or variant description</li>
<li>Added tool tip pop ups for the notes column. You can now hover over the notes field for a given issue and see it&#8217;s full value without having to select it or expand the notes field for all issues.</li>
<li>Cleaned up the display of the issues grid by displaying most common issue type (Regular), variant (No Variant) and printing (1st printing) as blanks. This looks much cleaner as there is more white space.</li>
<li>Added tool tips for Type, Variant and Printing Columns. Just hover over the column and the value for the Type Code or Variant Code will display in a tool tip for the issue. For printing a tool tip will only appear when the Printing field is blank in which case the tool tip will be &#8216;1st printing&#8217;. For example, hover over the Type Code of &#8216;Anl&#8217; and a tool tip will be &#8216;Annual&#8217;.</li>
<li>performed some general code factoring to make the code more maintainable.</li>
</ol>
</li>
</ol>
<img src="http://feeds.feedburner.com/~r/ComicBookUPCdb/~4/AusY1iI7H20" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://comicbookupcdb.com/blog/dsp-1-2-release-notes/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://comicbookupcdb.com/blog/dsp-1-2-release-notes</feedburner:origLink></item>
		<item>
		<title>Dev Sneak Peek vers 1.2</title>
		<link>http://feedproxy.google.com/~r/ComicBookUPCdb/~3/vs9sRQJ_bdI/dev-sneak-peek-vers-1-2</link>
		<comments>http://comicbookupcdb.com/blog/dev-sneak-peek-vers-1-2#comments</comments>
		<pubDate>Thu, 18 Mar 2010 05:39:39 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://comicbookupcdb.com/blog/?p=143</guid>
		<description><![CDATA[Just finished pushing out an updated version of the Developer Sneak Peek &#8230; check it out &#8211; I think this part of the site is close to being done.
I&#8217;ll blog about the improvements later as I&#8217;m tired and want to go to sleep!  
]]></description>
			<content:encoded><![CDATA[<p>Just finished pushing out an updated version of the <a title="Developer Sneak Peek Version 1.2" href="http://dev.comicbookupcdb.com/appl.php" target="_blank">Developer Sneak Peek</a> &#8230; check it out &#8211; I think this part of the site is close to being done.</p>
<p>I&#8217;ll blog about the improvements later as I&#8217;m tired and want to go to sleep! <img src='http://comicbookupcdb.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<img src="http://feeds.feedburner.com/~r/ComicBookUPCdb/~4/vs9sRQJ_bdI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://comicbookupcdb.com/blog/dev-sneak-peek-vers-1-2/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://comicbookupcdb.com/blog/dev-sneak-peek-vers-1-2</feedburner:origLink></item>
		<item>
		<title>Dev Sneak Peek v. 1.1</title>
		<link>http://feedproxy.google.com/~r/ComicBookUPCdb/~3/6mUA6XHmdM4/dev-sneak-peek-v-1-1</link>
		<comments>http://comicbookupcdb.com/blog/dev-sneak-peek-v-1-1#comments</comments>
		<pubDate>Sat, 06 Mar 2010 19:44:33 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://comicbookupcdb.com/blog/?p=139</guid>
		<description><![CDATA[Ok over the last week here I&#8217;ve put in some more development effort and have updated the Dev Sneak Peek to version 1.1!
I&#8217;ve completed all of the tables in the database and have loaded the rest of the test data for the issues. Granted this is just test data and I cannot go live with it, [...]]]></description>
			<content:encoded><![CDATA[<p>Ok over the last week here I&#8217;ve put in some more development effort and have updated the <a title="Try the new Dev Sneak Peak version 1.1!" href="http://dev.comicbookupcdb.com/appl.php" target="_blank">Dev Sneak Peek to version 1.1</a>!</p>
<p>I&#8217;ve completed all of the tables in the database and have loaded the rest of the test data for the issues. Granted this is just test data and I cannot go live with it, but here are the stats&#8230;</p>
<ul>
<li>publishers &#8211; 100</li>
<li>series (aka titles) &#8211; 20,401</li>
<li>issues &#8211; 271,797</li>
</ul>
<p>New functionality includes when you select a Title from the Series List on the left, the Series info is displayed on the top right and the list of issues for the selected Title is displayed on the lower right.</p>
<p>So what you ask? Good question&#8230; This screen represents what the main maintenance access screen will look like. You will come to this screen when you want to add a new issue or edit an existing one. I&#8217;ve still got to do some fine tuning of the Issue list, like formatting the columns, for example displaying the cover price as $2.95&#8230; There&#8217;s some other tweeking that I&#8217;d like to do to.</p>
<p>So try it out and leave a comment to this post to tell me what you think!</p>
<img src="http://feeds.feedburner.com/~r/ComicBookUPCdb/~4/6mUA6XHmdM4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://comicbookupcdb.com/blog/dev-sneak-peek-v-1-1/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://comicbookupcdb.com/blog/dev-sneak-peek-v-1-1</feedburner:origLink></item>
	</channel>
</rss>

