<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: High Tech Gift Exchange With PHP</title>
	<atom:link href="http://aarronwalter.com/2006/09/27/high-tech-gift-exchange-with-php/feed/" rel="self" type="application/rss+xml" />
	<link>http://aarronwalter.com/2006/09/27/high-tech-gift-exchange-with-php/</link>
	<description></description>
	<pubDate>Sun, 23 Nov 2008 12:34:19 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5</generator>
		<item>
		<title>By: Corinne</title>
		<link>http://aarronwalter.com/2006/09/27/high-tech-gift-exchange-with-php/#comment-57</link>
		<dc:creator>Corinne</dc:creator>
		<pubDate>Wed, 15 Nov 2006 17:58:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.aarronwalter.com/2006/09/27/high-tech-gift-exchange-with-php/#comment-57</guid>
		<description>Wow, thanks for the quick reply!  That worked, Merry Christmas to you as well!</description>
		<content:encoded><![CDATA[<p>Wow, thanks for the quick reply!  That worked, Merry Christmas to you as well!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aarron</title>
		<link>http://aarronwalter.com/2006/09/27/high-tech-gift-exchange-with-php/#comment-56</link>
		<dc:creator>Aarron</dc:creator>
		<pubDate>Wed, 15 Nov 2006 17:45:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.aarronwalter.com/2006/09/27/high-tech-gift-exchange-with-php/#comment-56</guid>
		<description>Corinne,

Probably what is causing this problem is the for loop. If you have 9 people, the for loop will look like this:

for($i=0;$i&lt;9;$i++){

$pull = rand(0,8);
while(in_array($pull,$drawn) or $i==$pull){ $pull = rand(0,8); }
array_push($drawn,$pull);

etc ...

The for loop needs to have $i set to the exact number of participants int eh gift exchange, and the random draw is one less than the total, because the array indexing starts at 0, so 9 people would each be assigned a number from 0 to 8 (9 numbers). Hope that makes sense.

A better way to do this would be to avoid hard-coding the number of participants, and having the script just count them for you. Here is what that might look like:

for($i=0;$i&lt;count($names);$i++){

$pull = rand(0,(count($names)-1));
while(in_array($pull,$drawn) or $i==$pull){ $pull = rand(0,(count($names)-1)); }
array_push($drawn,$pull);

etc ...

Good luck, and Merry early Christmas!</description>
		<content:encoded><![CDATA[<p>Corinne,</p>
<p>Probably what is causing this problem is the for loop. If you have 9 people, the for loop will look like this:</p>
<p>for($i=0;$i&lt;9;$i++){</p>
<p>$pull = rand(0,8);<br />
while(in_array($pull,$drawn) or $i==$pull){ $pull = rand(0,8); }<br />
array_push($drawn,$pull);</p>
<p>etc &#8230;</p>
<p>The for loop needs to have $i set to the exact number of participants int eh gift exchange, and the random draw is one less than the total, because the array indexing starts at 0, so 9 people would each be assigned a number from 0 to 8 (9 numbers). Hope that makes sense.</p>
<p>A better way to do this would be to avoid hard-coding the number of participants, and having the script just count them for you. Here is what that might look like:</p>
<p>for($i=0;$i<count($names);$i++){</p>
<p>$pull = rand(0,(count($names)-1));<br />
while(in_array($pull,$drawn) or $i==$pull){ $pull = rand(0,(count($names)-1)); }<br />
array_push($drawn,$pull);</p>
<p>etc &#8230;</p>
<p>Good luck, and Merry early Christmas!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Corinne</title>
		<link>http://aarronwalter.com/2006/09/27/high-tech-gift-exchange-with-php/#comment-55</link>
		<dc:creator>Corinne</dc:creator>
		<pubDate>Wed, 15 Nov 2006 17:35:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.aarronwalter.com/2006/09/27/high-tech-gift-exchange-with-php/#comment-55</guid>
		<description>This is great, I'm attempting to use it.  The only problem is, each time I almost always get one email that is blank for the name selection.  I have 9 people; might this have something to do with it?  I did change it to (0,8) in the $pull line, but it's still happening...

TIA.</description>
		<content:encoded><![CDATA[<p>This is great, I&#8217;m attempting to use it.  The only problem is, each time I almost always get one email that is blank for the name selection.  I have 9 people; might this have something to do with it?  I did change it to (0,8) in the $pull line, but it&#8217;s still happening&#8230;</p>
<p>TIA.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aarron</title>
		<link>http://aarronwalter.com/2006/09/27/high-tech-gift-exchange-with-php/#comment-23</link>
		<dc:creator>Aarron</dc:creator>
		<pubDate>Wed, 18 Oct 2006 11:12:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.aarronwalter.com/2006/09/27/high-tech-gift-exchange-with-php/#comment-23</guid>
		<description>Christopher,
You can add a conditional statements in the while loop to prevent drawing a name in a condition you do not want. It could be hard coded in or use another series of parallel arrays to match up people that can not draw eachother's name.</description>
		<content:encoded><![CDATA[<p>Christopher,<br />
You can add a conditional statements in the while loop to prevent drawing a name in a condition you do not want. It could be hard coded in or use another series of parallel arrays to match up people that can not draw eachother&#8217;s name.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Christopher</title>
		<link>http://aarronwalter.com/2006/09/27/high-tech-gift-exchange-with-php/#comment-22</link>
		<dc:creator>Christopher</dc:creator>
		<pubDate>Wed, 18 Oct 2006 06:39:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.aarronwalter.com/2006/09/27/high-tech-gift-exchange-with-php/#comment-22</guid>
		<description>Almost what I'm looking for.  However, there are certain people that I don't want paired up.  For example, I am already going to give my wife a present so I don't want to be matched with her.</description>
		<content:encoded><![CDATA[<p>Almost what I&#8217;m looking for.  However, there are certain people that I don&#8217;t want paired up.  For example, I am already going to give my wife a present so I don&#8217;t want to be matched with her.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
