<?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>The Infinite Loop - Beginner&#039;s SEO, Beginner C# &#38; JQuery Tutorials &#187; Databases</title>
	<atom:link href="http://theinfiniteloopblog.com/category/dbs/feed/" rel="self" type="application/rss+xml" />
	<link>http://theinfiniteloopblog.com</link>
	<description>Problem. Problem Solved. Loop. - The life of a programmer</description>
	<lastBuildDate>Wed, 17 Aug 2011 15:29:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>Easy, Simple Paging Using PHP</title>
		<link>http://theinfiniteloopblog.com/dbs/easy-simple-paging-using-php/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=easy-simple-paging-using-php</link>
		<comments>http://theinfiniteloopblog.com/dbs/easy-simple-paging-using-php/#comments</comments>
		<pubDate>Tue, 15 Sep 2009 07:10:16 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[custom php paging]]></category>
		<category><![CDATA[easy php paging]]></category>
		<category><![CDATA[how to php paging]]></category>
		<category><![CDATA[php automatic pagination]]></category>
		<category><![CDATA[php automatic paging]]></category>
		<category><![CDATA[php pagination]]></category>
		<category><![CDATA[php paging]]></category>
		<category><![CDATA[php paging tutorial]]></category>
		<category><![CDATA[simple php paging]]></category>

		<guid isPermaLink="false">http://scottmoniz.com/programmingBlog/?p=243</guid>
		<description><![CDATA[Easy &#38; Simple Paging using PHP. Here is the result: (DB has 8records, Rows per page is set to 5, and we're on page 2) Paging usually takes a while but here we will do it quickly and cleanly. Your page will be named page.php. And when we want to switch pages we will make [...]]]></description>
			<content:encoded><![CDATA[
<!-- ALL ADSENSE ADS DISABLED -->
<p style="text-align: center;">Easy &amp; Simple Paging using PHP. Here is the result: (DB has 8records, Rows per page is set to 5, and we're on page 2)<br />
<a href="http://coulditgetworse.com/theinfiniteloopblog/wp-content/uploads/2009/09/advertisers1.jpg"><img class="aligncenter size-full wp-image-252" title="advertisers" src="http://coulditgetworse.com/theinfiniteloopblog/wp-content/uploads/2009/09/advertisers1.jpg" alt="advertisers" width="489" height="128" /></a></p>
<p>Paging usually takes a while but here we will do it quickly and cleanly.</p>
<p>Your page will be named page.php. And when we want to switch pages we will make it page.php?pg=2.<br />
Im sure you've seen this before. Anyways lets dive in.</p>
<p>I use shorthand to clean stuff up, but basically shorthand is</p>
<p>$returnvalue=(condition ?  "true" : "false");<br />
Example:</p>
<p>$is_loggedin=(isset($_SESSION["loggedin"]) ? 1 : 0);<br />
After this statement, if the session variable is set, $is_loggedin will equal 1, else it will equal 0.</p>
<p>At the top of your PHP page type the following:</p>
<pre>&lt;?php
/*paging*/
Line 1: $pg=(isset($_GET["pg"]) &amp;&amp; is_numeric($_GET["pg"]) &amp;&amp; $_GET["pg"]&gt;0 ? $_GET["pg"] : 1);
Line 2: $rowsperpage=10;
Line 3: $offset=($pg&gt;1 ? ($pg-1)*$rowsperpage : 0 );
Line 4: $limitstr=" LIMIT $offset, $rowsperpage";
?&gt;</pre>
<p>Explanation:<br />
First of all Limit is : LIMIT $startrowid, $number of entries to return<br />
So LIMIT 55, 5  means start at row 55 and return 5 rows (55, 56, 57, 58, 59)</p>
<p><strong>Line 1</strong>: If in the query string the pg is set  e.g page.php?pg=4, and it is numeric, and greater than 0 we will assign the value of $_GET["pg"] to our $pg variable. If it is not set, or it is not numeric, or zero or less, we set the $pg variable to 1.<br />
<strong>Line 2</strong>: We set our rows per page<br />
<strong>Line 3</strong>: If the page is greater than 1, we set the offset to ($pg-1)*rowsperpage. If the page is 1 or less, we set offset to 0.<br />
<strong>Line 4</strong>: We create the limit string for the sql statement. This will output something like LIMIT x, y.<br />
(rowsperpage set to 10)</p>
<p>In this case page.php?pg=1<br />
$pg = 1;<br />
$offset = 0;<br />
$rowsperpage=10;<br />
$limitstr="LIMIT 0, 10"; //this string will pull 10 rows starting from row 0 (the first row) (rows 0-9)</p>
<p>In this case page.php?pg=3<br />
$pg=3;<br />
$offset= (3-1) * 10;  //offset calculates to 20<br />
$limitstr="LIMIT 20, 10";  //this string will pull 10 rows starting from  and including row 20 (rows 20-29)</p>
<p><strong>Ok. Now that we got that out of the way.</strong></p>
<p>We will use a simple query, then we will attach our new limit string (looking at case 2 above)<br />
$sql="SELECT * FROM MEMBERS $limitstr"; //sql = "SELECT * FROM MEMBERS LIMIT 20,10";<br />
$res=mysql_query($sql);<br />
while($row=mysql_fetch_array($res)){</p>
<p>//processing if you need to<br />
}</p>
<p>We also need to know the total count for this table<br />
$sql="SELECT COUNT(memberid) FROM MEMBERS";<br />
$res=mysql_query($sql);<br />
$row=mysql_fetch_array($res);<br />
$total = $row[0];</p>
<p>Now we know the total count.</p>
<p>So we need to calculate the number of pages. That is done by this formula:<br />
($total/$rowsperpage);<br />
Now in the case of 26 members and 5 rows per page. Using this formula 26/5 =  5.2pages, so we need to round up!</p>
<p>$maxpage=ceil($total/$rowsperpage); //max page is now 6.</p>
<p>Ok, we got everything set up <img src='http://theinfiniteloopblog.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Just need to print out our paging!<br />
Wherever you want your paging setup add this:</p>
<pre>&lt;?php
print '&lt;div class="paging"&gt;&lt;ul&gt;';
for($i=1; $i&lt;=$maxpage; $i++){
  if($pg==$i)
     print '&lt;li&gt;&lt;span&gt;'.$i.'&lt;/span&gt;&lt;/li&gt;';
  else
     print '&lt;li&gt;&lt;a href="?pg='.$i.'"&gt;'.$i.'&lt;/a&gt;&lt;/li&gt;';
}
print "&lt;/ul&gt;&lt;/div&gt;";
?&gt;</pre>
<p>Then we can do some nice styling (Mess around with margins to setup spacing)<br />
CSS<br />
div.paging {text-align: center; margin-top: 5px;}<br />
div.paging span{font-weight: bold;}<br />
div.paging ul{overflow: hidden;}<br />
div.paging ul li{width: 10px; float: left; margin: 0px 10px 5px 0px;}</p>
<p>This will page across until it hits the edge of the div, then it will move to the next line.</p>
<p>ENJOY and comment ! <img src='http://theinfiniteloopblog.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://theinfiniteloopblog.com/dbs/easy-simple-paging-using-php/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>USB Backup Utility with Batches</title>
		<link>http://theinfiniteloopblog.com/gen/usb-backup-utility-with-batches/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=usb-backup-utility-with-batches</link>
		<comments>http://theinfiniteloopblog.com/gen/usb-backup-utility-with-batches/#comments</comments>
		<pubDate>Thu, 14 May 2009 06:33:18 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[batch tips]]></category>
		<category><![CDATA[batch tricks]]></category>
		<category><![CDATA[batch utitilities]]></category>
		<category><![CDATA[usb]]></category>
		<category><![CDATA[usb backup utility]]></category>
		<category><![CDATA[utilities]]></category>
		<category><![CDATA[windows tips and tricks]]></category>

		<guid isPermaLink="false">http://scottmoniz.com/programmingBlog/?p=111</guid>
		<description><![CDATA[After my USB got FRIED behind the damn photocopier in the library a couple years ago, I had to re-do my whole Java Assignment AGAIN. I decided to make a little backup utility that would make it a little easier to back up my usb. It will only work if the pen drive is a [...]]]></description>
			<content:encoded><![CDATA[
<!-- ALL ADSENSE ADS DISABLED -->
<p>After my USB got FRIED behind the damn photocopier in the library a couple years ago, I had to re-do my whole Java Assignment AGAIN. I decided to make a little backup utility that would make it a little easier to back up my usb. It will only work if the pen drive is a fixed letter, but its always E: on my computer so thats fine by me. It consists on 2 files placed on the usb, a backup.bat that does the backing up and an autorun.inf which puts the Backup option into the autorun screen. When i plug my USB pen drive, the autorun gives me the option to backup, making an exact copy of my usb at c:/usb</p>
<p>Open notepad and paste this text in.</p>
<p><strong><span style="color: #3366ff;">@echo off<br />
echo                USB BACKUP UTILITY V1.0<br />
echo                    CREATED BY SCOTT<br />
echo ----------------------------------------------------------<br />
echo Starting Backup:<br />
cd \<br />
c:</span></strong></p>
<p><span style="color: #3366ff;"><strong>if exist c:\usb goto exists<br />
mkdir "USB"<br />
goto copy</strong></span></p>
<p><span style="color: #3366ff;"><strong>:exists<br />
rmdir "USB" /s /q<br />
mkdir "USB"</strong></span></p>
<p><span style="color: #3366ff;"><strong>:copy<br />
echo Date&gt;C:\usb\backup.txt<br />
date /t&gt;&gt;C:\usb\backup.txt<br />
echo.&gt;&gt;C:\usb\backup.txt<br />
echo Time&gt;&gt;C:\usb\backup.txt<br />
time /t&gt;&gt;C:\usb\backup.txt<br />
echo -------------------------------------------&gt;&gt;C:\usb\backup.txt</strong></span></p>
<p><span style="color: #3366ff;"><strong>cd \<br />
xcopy E:\* "C:\USB" /y /e /r /v&gt;&gt;C:\usb\backup.txt<br />
echo Backup Complete!<br />
echo.<br />
echo Backup of entire USB at C:/USB<br />
echo Log file placed at C:/USB/backup.txt<br />
echo ----------------------------------------------------------<br />
Pause</strong></span></p>
<p>In the line <strong><span style="color: #3366ff;">xcopy E:\* "C:\USB" /y /e /r /v&gt;&gt;C:\usb\backup.txt, </span></strong>replace E: in this line with your actual drive letter.<br />
<span style="color: #000000;">Save this file as backup.bat making sure that "All Files" is selected from the files drop down box.<br />
</span><strong><span style="color: #3366ff;"><br />
</span></strong></p>
<p><strong></strong><br />
<span style="color: #000000;">Next repeat the same steps, saving this text as autorun.inf</span></p>
<p><span style="color: #3366ff;"><strong>[autorun]<br />
action=Backup<br />
open=backup.bat<br />
label=MyUsbName<br />
includeRuntimeComponents=True</strong></span></p>
<p><span style="color: #000000;">Save both these files on the root of your USB.<br />
The next time you plug your usb in, you will see the autorun option "backup".<br />
By clicking this and hitting ok, a full usb backup will be performed and put in C:/USB<br />
</span></p>
]]></content:encoded>
			<wfw:commentRss>http://theinfiniteloopblog.com/gen/usb-backup-utility-with-batches/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing and Configuring MySql/Connecting with C#</title>
		<link>http://theinfiniteloopblog.com/dbs/mysql/installing-and-configuring-mysqlconnecting-with-c/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=installing-and-configuring-mysqlconnecting-with-c</link>
		<comments>http://theinfiniteloopblog.com/dbs/mysql/installing-and-configuring-mysqlconnecting-with-c/#comments</comments>
		<pubDate>Mon, 20 Apr 2009 05:26:06 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[c sharp]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://scottmoniz.com/programmingBlog/?p=42</guid>
		<description><![CDATA[Recently, I was asked to do some C# development with MySQL as the backend. Having C# with SQL Server 2005 development under my belt setting up a connection to a MySQL Server was pretty easy, however, I will walk you through the setup. Two packages you will need are the MySQL Essentials Installer(this installs the [...]]]></description>
			<content:encoded><![CDATA[
<!-- ALL ADSENSE ADS DISABLED -->
<p>Recently, I was asked to do some C# development with MySQL as the backend.<br />
Having C# with SQL Server 2005 development under my belt setting up a connection to a MySQL Server was pretty easy, however, I will walk you through the setup.</p>
<p>Two packages you will need are the MySQL Essentials Installer(this installs the server)<br />
and the MySQL Connecter/.NET Installer(this installs the bridge between MySQL and .NET)<br />
The third package, the GUI tools, is optional, but it is a lot easier to work with. (Think of it as a Management Studio Express, for those of you who have used SQL 2005)</p>
<p>MySQL Essentials Package: <a title="http://dev.mysql.com/downloads/mysql/5.1.html#downloads" href="http://dev.mysql.com/downloads/mysql/5.1.html#downloads" target="_blank">http://dev.mysql.com/downloads/mysql/5.1.html#downloads<br />
</a>MySqlConnector/NET: <a title="http://www.mysql.com/products/connector/net/" href="http://www.mysql.com/products/connector/net/" target="_blank">http://www.mysql.com/products/connector/net/</a><br />
MySQL Gui Tools: <a title="http://dev.mysql.com/downloads/gui-tools/5.0.html" href="http://dev.mysql.com/downloads/gui-tools/5.0.html" target="_blank">http://dev.mysql.com/downloads/gui-tools/5.0.html</a></p>
<p>Run the Essentials Package first, this package actually contains the server instance.<br />
Follow the prompts, they are pretty much straight forward.<br />
When you receive the prompt about your root password, pick a password.</p>
<p>Next install the MySQL Connector.<br />
Follow the prompts, they are pretty much straight forward as well, and should install pretty quickly.</p>
<p>From here, you can use the command line client located in Start&gt;Program Files&gt;MySql Version&gt;MySql Command Line Client, however, I choose to use the GUI tools instead.<br />
If you have not already, launch the GUI tools installer.</p>
<p>Once this is done, go to Start&gt;Program Files&gt;MySql Version#&gt;MySQL query browser<br />
Click the  ... button next to Stored Connection.<br />
Click New Connection.</p>
<p>Fill out the properties<br />
Connection: Name the connection<br />
Username: root<br />
Password: password used during setup<br />
Hostname: localhost<br />
Port: default is 3306<br />
Schema: specify the default database, you can leave this blank.</p>
<p>Click apply and close.<br />
In the connection screen, from the dropdown, pick the connection we just created.<br />
Type your password.<br />
If given a warning about a default schema, type  test or default in the Default Schema field, this will create<br />
a database named test or default. You can always delete this dummy database afterwards.</p>
<p>To create tables right click your database in the Schemata and click Create New Table.<br />
Most of the GUI is intuitive and should be picked up quite easy.</p>
<p><strong>Connecting to MySQL using C#</strong></p>
<p>Start a C# Application project (I'm using a Console App in my example)<br />
Right click your project and click Add Reference.<br />
Navigate to the Connector DLL.<br />
By default this dll is located at C:/Program Files/MySql/MySql Connector .NET Version#/Binaries/.NET 2.0/MySql.Data.dll</p>
<p>Once this is added add the line:<br />
using MySql.Data.MySqlClient;<br />
using System.Data; //for the ConnectionState enum<br />
to the top of your code.</p>
<p>Add this code to your main/load method:</p>
<p>//sets up the connection string<br />
string connString = "Server = localhost; Database = databaseName; Uid = root; Pwd = pass;";<br />
//creates a new MySqlConnection object<br />
MySqlConnection conn = new MySqlConnection(connString);</p>
<p>try{<br />
//try to open the connection, catch any exceptions<br />
conn.Open();<br />
//if the connection succeeds, print a msg<br />
Console.WriteLine("Connection Succeeded");<br />
}catch(Exception ex){<br />
//print that the connection failed, and the associated Message<br />
Console.WriteLine("Connection Failed: "+ex.Message);<br />
}finally{<br />
//if the connection is currently open, close it<br />
if(conn.State==ConnectionState.Open)<br />
conn.Close();<br />
}</p>
<p><strong>Troubleshooting:</strong></p>
<ul>
<li>If you are having trouble connecting, check your username and password.</li>
<li>Double check the connection string.</li>
<li>If you are sure the above is correct, make sure the MySql server instance is running. You can do this by</li>
<li>going to Start&gt;Run. Type services.msc and hit Ok. Scroll down the list to MySql, it should say started. If it does not, right click and hit Start.</li>
<li>Try to connect with the MySql GUI tools.</li>
</ul>
<p>Just about everything you can do with SQL Server you can do with MySql using the familiarly named classes:<br />
MySqlConnection, MySqlCommand, MySqlDataReader</p>
<p>Hope this gets you started on using MySql and C#.<br />
Any questions or comments, feel free to ask.</p>
]]></content:encoded>
			<wfw:commentRss>http://theinfiniteloopblog.com/dbs/mysql/installing-and-configuring-mysqlconnecting-with-c/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

