<?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>iD Tech Camps &#187; mysql</title>
	<atom:link href="http://www.internaldrive.com/tag/mysql/feed/" rel="self" type="application/rss+xml" >
	<link>http://www.internaldrive.com</link>
	<description>Summer Computer Camps for Kids, Teens &#38; Youth</description>
	<lastBuildDate>Mon, 06 Feb 2012 20:14:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Making a Poll in PHP from Scratch: Part 1</title>
		<link>http://www.internaldrive.com/2009/05/14/making-a-poll-in-php-from-scratch-part-1/</link>
		<comments>http://www.internaldrive.com/2009/05/14/making-a-poll-in-php-from-scratch-part-1/#comments</comments>
		<pubDate>Thu, 14 May 2009 16:16:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[iD Tech Bloggers]]></category>
		<category><![CDATA[internet poll]]></category>
		<category><![CDATA[internet polls]]></category>
		<category><![CDATA[internet voting]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[php mysql]]></category>
		<category><![CDATA[php poll]]></category>
		<category><![CDATA[poll]]></category>
		<category><![CDATA[voting]]></category>

		<guid isPermaLink="false">http://www.internaldrive.com/?p=22676</guid>
		<description><![CDATA[There are plenty of ready-made Internet polls out there, particularly if you are using a framework for your site such as WordPress, vBulletin, or Joomla/Drupal. But occasionally it is worthwhile to create your own from scratch, whether for learning or to simply fulfill specific features you need in your application. In this series of posts, [...]]]></description>
			<content:encoded><![CDATA[<p>There are plenty of ready-made Internet polls out there, particularly if you are using a framework for your site such as WordPress, vBulletin, or Joomla/Drupal. But occasionally it is worthwhile to create your own from scratch, whether for learning or to simply fulfill specific features you need in your application. In this series of posts, that is exactly what we will create &#8211; a homemade PHP/MySQL voting page. You should be then able to modify this code for your specific needs.</p>
<p>First, let&#8217;s talk about the inherent flaws in Internet voting. In the most basic form, an Internet poll is just a choice a person makes on a page that is stored in the database. Without any checks, a person could just refresh the page and vote over and over again. Or, worse, they could employ a script of their own that does this automatically. You could potentially register millions of votes this way, given enough time. So what checks and balances do we have? There are three main options.</p>
<h2>User Login</h2>
<p>A user login system is the most secure of your options, especially if the accounts are linked to a unique email address. If you are using a system like WordPress or Drupal, then it is trivial to store the userid of the voter in the database as well. Do you want to use this option with your poll? If the user is already logging in for other reasons, then this is probably fine. Making a user register just to vote in a poll brings the convenience factor way down, most likely deterring most people. Plus, is it really worth it? If a user has the time and inclination, they can simply register over and over again, especially if they have their own domain or email server from which to pull infinite accounts. You could employ some IP-checking with your account checks to make sure they are unique, but then it just becomes an arms race. This option is too burdernsome for us to use in this project.</p>
<h2>Cookies</h2>
<p>We could use cookies set on a person&#8217;s machine to determine whether they&#8217;ve voted or not, but all it takes is a browser switch, cleared cache, or a privacy mode and suddenly our checking goes right out the window. This option is almost too simple for the user to overcome.</p>
<h2>IP Address</h2>
<p>The last major option is an IP address check. There are several flaws with this method, like the others, but we can overcome a few of them more easily. First, IP addresses are not a one-address-to-one-person mapping. The system can go either way, in fact. You can have multiple IPs for a single person, if they have multiple systems, a cellphone, so on. You can also have multiple people for an IP, in the case of a corporate network. You could have 10,000 people registering as a single IP. But these are problems we can find workarounds for.  We&#8217;ll use IP checking in conjuction with a few tricks as our authentication method.</p>
<h2>Database Structure: Your Favorite Fruit</h2>
<p>For this poll, I&#8217;m creating two different database tables, <strong>mypoll</strong> and <strong>mypolltally</strong>. The first table will contain all of the choices in our poll and the second the individual votes. This means that we can only have a single poll at a time, but this is a trivial matter in the future to extend (we would simply add another column to <strong>mypoll</strong>, <em>pollid</em>, containing a unique identifier. Then we would just need a column in mypolltally to store the <em>pollid</em> of each vote).</p>
<pre>         mypoll                                 mypolltally
--------------------------      --------------------------------------------
| id |      choice       |      | id | isvotefor |    ipaddress    | value |
--------------------------      --------------------------------------------
| 0  | banana            |      | 0  |     3     | 255.255.255.255 |   1   |
| 1  | apple             |      | 1  |     4     | 254.255.255.255 |   1   |
| 2  | orange            |      | 2  |     1     | 251.255.255.255 |   1   |
| 3  | strawberry        |      | 3  |     2     | 252.255.255.255 |   1   |
| 4  | blueberry         |      | 4  |     2     | 253.255.255.255 |   1   |
--------------------------      --------------------------------------------</pre>
<h2>The Fields</h2>
<p><strong>mypoll:</strong></p>
<ul>
<li><strong>id</strong>: A unique identifier for records in the table. When we register a vote in <strong>mypolltally</strong>, we&#8217;ll need to know which option we are voting for. We&#8217;ll use this value to do so.</li>
<li><strong>choice</strong>: The text for each option. Our poll question is &#8220;What is your favorite fruit?&#8221;, so here we lay out the choices such as</li>
<li><em>banana</em>, <em>apple</em>, and <em>orange</em>.</li>
</ul>
<p><strong>mypolltally:</strong></p>
<ul>
<li><strong>id</strong>: A unique identifier for each vote in the system.</li>
<li><strong>isvotefor</strong>: This field points identifies which option in <strong>mypoll</strong> that this vote is selecting.</li>
<li><strong>ipaddress</strong>:The IP address of the voter.</li>
<li><strong>value</strong>:We can extend our features a little by having this field. Instead of simply registering a &#8220;Yes&#8221; for a particular option, we can register a range. We can then allow people to indicate <em>how much</em> they like the option. Perhaps a <strong>1</strong> value is a little, a <strong>5</strong> value is a lot, and anything negative means they do not like it. For now, a value of <strong>1</strong> will just mean yes but later we&#8217;ll extend it for enhanced voting.</li>
</ul>
<p>That&#8217;s enough of the theory for now. In the next part of the series we&#8217;ll launch into the actual PHP code and finish up with the basic functionality. In Part 3 we&#8217;ll extend our code to allow for more features.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.internaldrive.com/2009/05/14/making-a-poll-in-php-from-scratch-part-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Integrating Flickr with vBulletin</title>
		<link>http://www.internaldrive.com/2009/04/30/integrating-flickr-with-vbulletin/</link>
		<comments>http://www.internaldrive.com/2009/04/30/integrating-flickr-with-vbulletin/#comments</comments>
		<pubDate>Thu, 30 Apr 2009 17:40:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[iD Tech Bloggers]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[changes]]></category>
		<category><![CDATA[Classes]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Flickr]]></category>
		<category><![CDATA[Flickr API]]></category>
		<category><![CDATA[Manager]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[Objects]]></category>
		<category><![CDATA[photo]]></category>
		<category><![CDATA[photos]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[phpFlickr]]></category>
		<category><![CDATA[style]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[vBulletin]]></category>

		<guid isPermaLink="false">http://www.internaldrive.com/?p=22446</guid>
		<description><![CDATA[Our support forums here at iD Tech run on the popular internet forum software, vBulletin. Each year we constantly revamp the system with new upgrades, a new design, and new code plugins to make the process more specific to our business model and more accessible to our staff. In addition, we also have a public [...]]]></description>
			<content:encoded><![CDATA[<p>Our support forums here at iD Tech run on the popular internet forum software, <a title="vBulletin" href="http://www.vbulletin.com" target="_blank">vBulletin</a>. Each year we constantly revamp the system with new upgrades, a new design, and new code plugins to make the process more specific to our business model and more accessible to our staff.</p>
<p>In addition, we also have a public Flickr stream. I wanted to pull these two elements together so that we could bring examples of our Flickr photos to our own support system. Here&#8217;s how I integrated them.</p>
<ol style="padding-left: 30px;">
<li>Download the phpFlickr API from here: http://www.phpflickr.com/</li>
<li>Unzip the files to your vBulletin <strong>/includes/</strong> folder.</li>
<li>If you want, you can rename the files to match the vBulletin naming convention (i.e. phpflickr.php -&gt; functions_phpflickr.php).</li>
<li><strong>Optional: </strong>Create a new vBulletin product. From the admin side, choose <strong>Manage Products</strong> from the <strong>Plugins &amp; Products </strong>menu. Then select <strong>Add/Import</strong> product. Fill in the information you need for a new product and hit save.</li>
<li> Add a new vBulletin plugin. From the <strong>Plugins &amp; Products </strong>admin menu, select <strong>Add New Plugin</strong>. Select the product you created in <strong>Step 4</strong>, or <strong>vBulletin</strong> otherwise. For hook location, you&#8217;ll need to select where you want the Flickr photos displayed. I&#8217;m placing them on our vBulletin homepage, so I select <strong>forumhome_start </strong>for my hook. Enter a title (such as <strong>Flickr Integration</strong>), leave the exectution order alone, and use the PHP code shown below.</li>
<li>From the <strong>Styles &amp; Templates </strong>menu, select <strong>Style Manager</strong>. Pick your style and choose <strong>Edit Templates</strong>. Find <strong>FORUMHOME </strong>(or whichever style is applicable to the hook location you chose) and double-click on it.</li>
<li> Find the location in the template where you want your photos displayed and enter <strong>$flickrbox</strong>, the name of the variable we are pulling from our PHP plugin.</li>
</ol>
<p>Now let&#8217;s take a look at the code we&#8217;re placing in our plugin.</p>
<pre style="padding: 30px 0px 30px 30px;">require_once("includes/phpFlickr.php");

// Create new phpFlickr object
$f = new phpFlickr("yourapikey");
$f-&gt;enableCache("db","mysql://user:password@server/database");

$limit = 11;

// Find the NSID of the username inputted via the form
$person = $f-&gt;people_findByUsername('iDTechCamp');

// Get the friendly URL of the user's photos
$photos_url = $f-&gt;urls_getUserPhotos($person['id']);

// Get the user's first X($limit) public photos
$photos = $f-&gt;people_getPublicPhotos($person['id'], NULL, NULL, $limit);
$flickrbox = "&lt;table class='flickrbox'&gt;&lt;tr&gt;";

// Loop through the photos and output the html
foreach ((array)$photos['photos']['photo'] as $photo) {
    $flickrbox .= "&lt;td&gt;&lt;a class='flickrimg' href=$photos_url$photo[id]&gt;";
    $flickrbox .= "&lt;img border='0' alt='$photo[title]' "
               ."src=" . $f-&gt;buildPhotoURL($photo, "Square") . "&gt;";
    $flickrbox .= "&lt;/a&gt;&lt;/td&gt;";
}

$flickrbox .= "&lt;/tr&gt;&lt;/table&gt;";</pre>
<p>First, we <strong>require_once</strong> the phpflickr php api library. Alter this line if you choose to name your library differently. Next, we create a new phpFlickr object, <strong>$f</strong>, and supply our Flickr API key. Change this line to reflect your unique API key. Next, we optionally enable the cache available with this library by supplying our mySQL database details. If you don&#8217;t have your details, don&#8217;t worry, this step isn&#8217;t required.</p>
<p>We then set a limit for how many photos we want. I&#8217;ve chosen 11. We use <strong>people_findByUsername</strong> to get photos for our particular user, in this case, the company username <strong>iDTechCamp</strong>. The resulting statements will pull <strong>$limit</strong> number of photos from the public profile of our user. Lastly, we need to construct a variable that holds the output as HTML. Our variable here is <strong>$flickrbox</strong> and as you can see I&#8217;m generating a table with CSS class style named <strong>flickrbox</strong>. Each image in the table is table cell and contains a link to that particular image. We also set the image title to the photo title pulled from <strong>Flickr</strong>.</p>
<p>You can easily alter the PHP code here to produce tableless HTML or any other structure you like. I hope these instructions help you to integrate your board and Flickr! Email me or comment with any questions you might have.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.internaldrive.com/2009/04/30/integrating-flickr-with-vbulletin/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Populating a Combo-box in PHP Dynamically from MySQL</title>
		<link>http://www.internaldrive.com/2009/03/31/populating-a-combo-box-in-php-dynamically-from-mysql/</link>
		<comments>http://www.internaldrive.com/2009/03/31/populating-a-combo-box-in-php-dynamically-from-mysql/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 16:30:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[iD Tech Bloggers]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[combo-box]]></category>
		<category><![CDATA[drop-down box]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.internaldrive.com/?p=21898</guid>
		<description><![CDATA[For this article, let&#8217;s pretend you have the following database table. There are two columns (I&#8217;m separating the fields with commas for readability), Item and Price: Cheese Pizza, 1.00 Pepporoni Pizza, 1.50 Sausage Pizza, 1.50 Cheese Calzone, 1.50 Ham Calzone, 2.00 What if you want to populate a combo-box with your possible options? We can [...]]]></description>
			<content:encoded><![CDATA[<p>For this article, let&#8217;s pretend you have the following database table. There are two columns (I&#8217;m separating the fields with commas for readability), Item and Price:</p>
<p>Cheese Pizza, 1.00<br >
Pepporoni Pizza, 1.50<br >
Sausage Pizza, 1.50<br >
Cheese Calzone, 1.50<br >
Ham Calzone, 2.00</p>
<p>What if you want to populate a combo-box with your possible options? We can write php that generates a drop-down box that has five item choices in it, based on our table above. Here is the sample code:</p>
<pre>&lt;?php

  // Connect to the database
  mysql_connect("localhost", "user", "password") or die(mysql_error());
  mysql_select_db("name") or die(mysql_error());

  // Has the form been submitted?
  if (isset($_POST['item'])) {

    // The form has been submitted, query results
    $queryitem = "SELECT * FROM table WHERE item = '".$_POST['item']."';";

    // Successful query?
    if($result = mysql_query($queryitem))  {

      // More than 0 results returned?
      if($success = mysql_num_rows($result) &gt; 0) {

        // For each result returned, display it
        while ($row = mysql_fetch_array($result)) echo $row[serial];
      }
      // Otherwise, no results, tell user
      else { echo "No results found."; }
    }
    // Error connecting? Tell user
    else { echo "Failed to connect to database."; }
  }
  // The form has NOT been submitted, so show the form instead of results
  else {

    // Create the form, post to the same file
    echo "&lt;form method='post' action='example.php'&gt;";

    // Form a query to populate the combo-box
    $queryitem = "SELECT DISTINCT item FROM table;";

    // Successful query?
    if($result = mysql_query($queryitem))  {

      // If there are results returned, prepare combo-box
      if($success = mysql_num_rows($result) &gt; 0) {
        // Start combo-box
        echo "&lt;select name='item'&gt;n";
        echo "&lt;option&gt;-- Select Item --&lt;/option&gt;n";

        // For each item in the results...
        while ($row = mysql_fetch_array($result))
          // Add a new option to the combo-box
          echo "&lt;option value='$row[item]'&gt;$row[item]&lt;/option&gt;n";

        // End the combo-box
        echo "&lt;/select&gt;n";
      }
      // No results found in the database
      else { echo "No results found."; }
    }
    // Error in the database
    else { echo "Failed to connect to database."; }

    // Add a submit button to the form
    echo "&lt;input type='submit' value='Submit' /&gt;&lt;/form&gt;";
  }
?&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.internaldrive.com/2009/03/31/populating-a-combo-box-in-php-dynamically-from-mysql/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

