<?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>IT Answers &#187; associative array</title>
	<atom:link href="http://itknowledgeexchange.techtarget.com/itanswers/tag/associative-array/feed/" rel="self" type="application/rss+xml" />
	<link>http://itknowledgeexchange.techtarget.com/itanswers</link>
	<description></description>
	<lastBuildDate>Thu, 20 Jun 2013 02:09:04 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Parsing error: Declare and initialize an associative array</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/parsing-error-declare-and-initialize-an-associative-array/</link>
		<comments>http://itknowledgeexchange.techtarget.com/itanswers/parsing-error-declare-and-initialize-an-associative-array/#comments</comments>
		<pubDate>Wed, 17 Mar 2010 01:24:58 +0000</pubDate>
		<dc:creator>PatOswalt</dc:creator>
				<category><![CDATA[associative array]]></category>
		<category><![CDATA[codeLobster]]></category>
		<category><![CDATA[parsing error]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Text field; table; output; fopen]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Used an HTML form to create a table.  Saved the data using &#60;html&#62;     &#60;!--Patricia Oswalt - IT250 Unit 4 Assignment--&#62;         &#60;head&#62;         &#60;title&#62;Save Directory&#60;/title&#62;     &#60;/head&#62;           &#60;body&#62;         &#60;?php                 //initializing the variables         $LastName = ($_POST['LastName']);         $FirstName = ($_POST['FirstName']);     [...]]]></description>
				<content:encoded><![CDATA[<p>Used an HTML form to create a table.  Saved the data using </p>
<pre>&lt;html&gt;
    &lt;!--Patricia Oswalt - IT250 Unit 4 Assignment--&gt;
    
    &lt;head&gt;
        &lt;title&gt;Save Directory&lt;/title&gt;
    &lt;/head&gt;
     
    &lt;body&gt;

        &lt;?php
        
        //initializing the variables
        $LastName = ($_POST['LastName']);
        $FirstName = ($_POST['FirstName']);
        $StreetAdd = ($_POST['StreetAdd']);
        $City = ($_POST['City']);
        $State = ($_POST['State']);
        $ZipCode = ($_POST['ZipCode']);
        $PhoneNum = ("(" . $_POST['AreaCode'] . ")" . $_POST['Prefix'] . "-" . $_POST['LineNum']);
            
        //confirming that all variables will contain values
        if (empty($LastName) ||
            empty($FirstName) ||
            empty($StreetAdd) ||
            empty($City) ||
            empty($State) ||
            empty($ZipCode) ||
            empty($PhoneNum))
            echo "&lt;p&gt;You must completely fill out the form.  Please use your browser's Back button to return to the form.&lt;/p&gt;";

        else 
        //creating, writing and saving to the text file.
        $NewContact = 'contactlist.txt';
        $Contact = fopen($NewContact, 'a+');
        $output = "$LastName, $FirstName, $StreetAdd, $City, $State, $ZipCode, $PhoneNum rn";
        echo "New Contact Saved Successfully!";
        fwrite($Contact, $output);
        fclose($Contact);

        ?&gt;

    &lt;p&gt;&lt;a href="InputTelephone.html"&gt;Add New Listing&lt;/a&gt;&lt;/p&gt;
    &lt;p&gt;&lt;a href="contactlist.txt"&gt;Retrieve Contact List&lt;/a&gt;&lt;/p&gt;

    &lt;/body&gt;

&lt;/html&gt;</pre>
<p>The above works fine.  Now I have to be able to sort the data in a table.</p>
<p>This is my code so far.</p>
<pre>&lt;html&gt;
    &lt;!--Patricia Oswalt - IT250 Unit 5 Assignment--&gt;
    
    &lt;head&gt;
        &lt;title&gt;Contact Table&lt;/title&gt;
    &lt;/head&gt;
     
    &lt;body&gt;

    &lt;?php
    //opening the file for reading
    $fp = fopen('contactlist.txt', 'r');
    if(!$fp) die ("Cannot open the file");
    
    <b>//Declare and initialize an associative array
</b>
    $Listing = array();
    $Listing[$Name] = $LastName, $FirstName;
    $Listing[$Number] = $PhoneNum;

<b>//Is the above syntax correct to create an associative array named $Listing?</b>

  echo "&lt;table border='1'&gt;";
  echo "&lt;tr&gt;";
  echo "&lt;th&gt;Name&lt;/th&gt;";
  echo "&lt;th&gt;Phone Number&lt;/th&gt;";
  echo "&lt;/tr&gt;";
  
      //Next we want to sort $Listing by the $LastName
    ksort($Listing);

    //Then to print the sorted table. (using the example in Unit 5’s slide show)
        foreach($Listing as $Name =&gt; $Number)
        {
            echo "&lt;tr&gt;";
            echo "&lt;td&gt;$Name&lt;/td&gt;";
            echo "&lt;td&gt;$Number&lt;/td&gt;&lt;br&gt;";
            echo "&lt;/tr&gt;";
        }
        echo "&lt;/table&gt;";
    ?&gt;

    &lt;p&gt;&lt;a href="InputTelephone.html"&gt;Add New Listing&lt;/a&gt;&lt;/p&gt;
    &lt;p&gt;&lt;a href="contactlist.txt"&gt;Retrieve Contact List&lt;/a&gt;&lt;/p&gt;
    
    &lt;/body&gt;

&lt;/html&gt;</pre>
<p>I think my only problem is creating the associative array.  Can anyone look it over and tell me if they see any problems?  This project is already a week behind and I can&#8217;t figure out where I&#8217;m going wrong.</p>
<p>Looking over it right now, I think I made need to put an fclose statement somewhere as well.</p>
<p>Thanks in advance!  Patricia</p>
<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/itanswers/parsing-error-declare-and-initialize-an-associative-array/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using memcached
Database Caching 3/14 queries in 0.019 seconds using memcached
Object Caching 314/335 objects using memcached

Served from: itknowledgeexchange.techtarget.com @ 2013-06-20 06:37:03 -->