<?xml version="1.0" encoding="utf-8" ?><rss version="2.0" xml:base="https://www.webmaster-forums.net/crss/node/1038817" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title></title>
    <link>https://www.webmaster-forums.net/crss/node/1038817</link>
    <description></description>
    <language>en</language>
          <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/php-session-count-problem#comment-1221310</link>
    <description> &lt;p&gt;Amen!  I&#039;m glad I could be that spark...  funny, that&#039;s what I was trying to do.... &lt;img src=&quot;https://www.webmaster-forums.net/misc/smileys/wink.png&quot; title=&quot;Wink&quot; alt=&quot;Wink&quot; class=&quot;smiley-content&quot; /&gt;&lt;/p&gt;
 </description>
     <pubDate>Fri, 06 Jul 2007 18:20:46 +0000</pubDate>
 <dc:creator>brady.k</dc:creator>
 <guid isPermaLink="false">comment 1221310 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/php-session-count-problem#comment-1221302</link>
    <description> &lt;p&gt;thanks brady.k for the interest and help and most definitely the ideas&lt;br /&gt;
I have tried a whole new approach and it works fine&lt;br /&gt;
(looks like variables have become more clear to me than I thought)&lt;/p&gt;
&lt;p&gt;You saying to forget the explode gave me the idea to loop and get all session data and add it to a variable within the loop&lt;br /&gt;
Then just use that variable in the simple if/else.&lt;/p&gt;
&lt;blockquote class=&quot;bb-quote-body&quot;&gt;&lt;p&gt;Quote: function basketqty() {&lt;br /&gt;
foreach($_SESSION[&#039;cart&#039;] as $product_id =&amp;gt; $quantity) {&lt;br /&gt;
$qtycount = $qtycount + $quantity;&lt;br /&gt;
}&lt;/p&gt;
&lt;p&gt;if (!$qtycount) {&lt;br /&gt;
return &#039;Your Basket (0 Items)&#039;;&lt;br /&gt;
} elseif ($qtycount==1) {&lt;br /&gt;
return &#039;Your Basket (1 Item)&#039;;&lt;br /&gt;
} else {&lt;br /&gt;
		return &quot;Your Basket ($qtycount items)&quot;;&lt;br /&gt;
}&lt;br /&gt;
}&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Sincerely thanks for the help, but as is often mentioned on this and other forums, there is nothing more rewarding than solving something yourself.&lt;/p&gt;
&lt;p&gt;Cheers&lt;/p&gt;
 </description>
     <pubDate>Fri, 06 Jul 2007 16:51:43 +0000</pubDate>
 <dc:creator>greg</dc:creator>
 <guid isPermaLink="false">comment 1221302 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/php-session-count-problem#comment-1221256</link>
    <description> &lt;p&gt;Ok, I don&#039;t know if this will get you anywhere, but as far as I know, you should use &lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #000000&quot;&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;&amp;lt;?php&lt;br /&gt;$product_id &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;striptags&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$_GET&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;id&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;])&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;  (notice the single quotes... I&#039;m not sure it works without them)&lt;/p&gt;
&lt;p&gt;I would stop using the &quot;explode&quot; statement.  Because (unless I&#039;m blind), I don&#039;t see anywhere that you&#039;re adding commas.  As far as I can tell, you&#039;re just pulling info from a session, and then looking at the numeric value inside.  Right?&lt;/p&gt;
&lt;p&gt;So what I would do is just write a loop to pull out all of those values, and work with that.  So maybe you have&lt;br /&gt;
&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #000000&quot;&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;&amp;lt;?php&lt;br /&gt;$cart_arr &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= array();&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$count &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;br /&gt;
and then use $cart_arr to store those values pulled from the session, leaving NULL values where there aren&#039;t any requests... but do it sequentially.  So if you had values for item id 1 and 2, but that was it, your array would look like&lt;br /&gt;
&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #000000&quot;&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;&amp;lt;?php&lt;br /&gt;$count_arr&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;] = &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;whatever&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$count_arr&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;] = &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;whatever&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$count_arr&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;] = &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;and then because you have a specific count (aka number) of things, you know where to stop.&lt;/p&gt;
&lt;p&gt;I can&#039;t really write anything in total for you because I don&#039;t have all your code, and I don&#039;t fully understand your layout, but I think my suggestion should work.  Get rid of the &#039;explode&#039; and just use some sort of counting system instead... because you don&#039;t ever insert any commas anywhere.&lt;/p&gt;
&lt;p&gt;See what you can do, and come back with some more.  We&#039;ll go from there.&lt;/p&gt;
 </description>
     <pubDate>Thu, 05 Jul 2007 18:52:41 +0000</pubDate>
 <dc:creator>brady.k</dc:creator>
 <guid isPermaLink="false">comment 1221256 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/php-session-count-problem#comment-1221250</link>
    <description> &lt;p&gt;thanks for the reply&lt;/p&gt;
&lt;blockquote class=&quot;bb-quote-body&quot;&gt;&lt;p&gt;Quote: Here&#039;s a question.... when you do explode(&#039;,&#039;....); does that assume that you have a comma after every item? ....&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;I am unsure to be honest. I am still learning about sessions/arrays and functions&lt;br /&gt;
(variables are only just sinking in)&lt;/p&gt;
&lt;p&gt;when i print the array (session) it looks like this&lt;/p&gt;
&lt;p&gt;Array ( [2] =&amp;gt; 11 [1] =&amp;gt; 1 ) &lt;/p&gt;
&lt;p&gt;[2] is the id in mysql database  11 is the current quantity ($quantity)of that item in the cart (or session)&lt;br /&gt;
so [1] is id one in the database and currently there is only one of those items in the basket&lt;/p&gt;
&lt;p&gt;the id from mysql is gained from a simple link:&lt;br /&gt;
&lt;a href=&quot;cart.php?action=add&amp;amp;id=&amp;#039;.$row[&amp;#039;id&amp;#039;].&amp;#039;&quot;&gt;Add to cart&lt;/a&gt;&#039;;&lt;br /&gt;
this is within the while command:&lt;br /&gt;
while($row = mysql_fetch_array( $result ))&lt;/p&gt;
&lt;p&gt;(basically while is to print all the products in the database to the table)&lt;/p&gt;
&lt;p&gt;then&lt;br /&gt;
$product_id = $_GET[id];&lt;/p&gt;
&lt;p&gt;and there is a&lt;br /&gt;
switch($action) {&lt;/p&gt;
&lt;p&gt;         case &quot;add&quot;: $_SESSION[&#039;cart&#039;][$product_id]++;&lt;/p&gt;
&lt;p&gt;case delete and remove all items, which both use unset, either unset [$product_id] ==0 or unset the whole $_SESSION[&#039;cart&#039;]&lt;/p&gt;
&lt;p&gt;I just dont know&lt;br /&gt;
It seems somehow as if the function i have (as per first post) is checking the session for null or notnull?!?&lt;br /&gt;
I think that because it works for 0 items (session is empty) and works for 1 items&lt;br /&gt;
but more than one item it doesnt work&lt;br /&gt;
regardless of if its 3 of one product (mysql id 1) or 2 of one product and 1 of another&lt;/p&gt;
&lt;p&gt;So you maybe right about the way i have stated the session items are speperated, but i have no idea how to determine what would be correct&lt;/p&gt;
&lt;p&gt;also, to me, I would have thought :&lt;br /&gt;
$itemcount = $_SESSION[&#039;cart&#039;];&lt;br /&gt;
which is the bit of the function i am having problems with, would need to be more&lt;br /&gt;
like it should specify somehow the actual quantity. I mean, how does it know to take the quantity numbers form all products stored in the session?&lt;/p&gt;
&lt;p&gt;Cheers&lt;/p&gt;
 </description>
     <pubDate>Thu, 05 Jul 2007 17:53:21 +0000</pubDate>
 <dc:creator>greg</dc:creator>
 <guid isPermaLink="false">comment 1221250 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/php-session-count-problem#comment-1220989</link>
    <description> &lt;p&gt;Well, I would assume that if it only screws up when theres more than one item... then it would have to be:&lt;br /&gt;
&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #000000&quot;&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;&amp;lt;?php&lt;br /&gt;$count &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;explode&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;,&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$itemcount&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$s &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= (&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;count&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$count&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;) &amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;) ? &lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;s&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;;&lt;br /&gt;return &lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;Your Basket (&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;count&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$count&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;).&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039; item&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$s&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;)&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;br /&gt;
...right?&lt;/p&gt;
&lt;p&gt;Here&#039;s a question.... when you do explode(&#039;,&#039;....); does that assume that you have a comma after every item?  Does that follow through your whole code?  So if you have two items, it looks like:&lt;br /&gt;
&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;whatever,whatever,&lt;/code&gt;&lt;/div&gt;&#039;&lt;br /&gt;
...because that&#039;s what I would assume.  And if that&#039;s the case, then you may want to check to make sure you follow that logic throughout.&lt;/p&gt;
&lt;p&gt;(side note, I would never have known what &quot;(count($count) &amp;gt; 1) ? &#039;s&#039;:&#039;&#039;;&quot; meant because of how you structured it if it wasn&#039;t for knowing a fair amount of C... I had no idea that structure/syntax was supported in PHP?...)&lt;/p&gt;
&lt;p&gt;Other than your potential logic problem, I don&#039;t see any glaring issues.  Everything seems to revolve around the explode statement, so I would examine that and it&#039;s associated session data closely...&lt;/p&gt;
&lt;p&gt;Hopefully that helps a little bit.  If not, come back and we&#039;ll try again....  Good luck!&lt;/p&gt;
 </description>
     <pubDate>Fri, 29 Jun 2007 14:07:48 +0000</pubDate>
 <dc:creator>brady.k</dc:creator>
 <guid isPermaLink="false">comment 1220989 at https://www.webmaster-forums.net</guid>
  </item>
  </channel>
</rss>
