-1

I'm building a shopping cart php file that will query a database for products (and the quantity of each product a user adds to the shopping cart). But I'm having trouble understanding what to do with a "comma-delimited string". Here's the loop in my code so far:

//Loop through your cart array (foreach productID's quantity in cart):
     $_SESSION['numItems'] = $cart;//Update the number of items in your cart

     //Build a comma-delimited string in $prodIDStr containing the product
     //ID’s of the products currently in our cart array:
     $prodIDStr = "";//STACKOVERFLOW QUESTION


     if($_SESSION[numItems] = 0){//If cart it empty:
         print "<h3>Your shopping cart is empty!</h3>\n";
     }
     Else{//if cart is not empty:

         //remove trailing comma from $prodIDstr:

What exactly is a comma-delimited string, and what does removing a trailing comma do?

Sam Peterson
  • 107
  • 1
  • 9

2 Answers2

0

1) This question is best answered by a Google search: https://www.google.com/search?q=what+is+a+comma+delimineted+string&sourceid=ie7&rls=com.microsoft:en-us:IE-SearchBox&ie=&oe=#rls=com.microsoft:en-us:IE-SearchBox&q=what+is+a+comma+delimited+string&spell=1&sa=X&ei=S6yGUdmUMMS60QHvmoHwBg&ved=0CC0QvwUoAA&bav=on.2,or.r_qf.&bvm=bv.45960087,d.dmQ&fp=2bfada69378a0dbe&biw=1680&bih=938

If you have different values, such as name and phone number, you would separate them by a comma: Name,PhoneNumber

2) This question is intuitive when you know what CSV is. If the last character is a comma, then removing a trailing comma deletes the comma.

Name,PhoneNumber, removes the last ,

phpmeh
  • 1,752
  • 2
  • 22
  • 41
  • Not to be lazy, but in php syntax, how do you remove a trailing comma from a csv statement (single line of code, NOT a csv file)? – Sam Peterson May 05 '13 at 19:12
  • Search before asking my friend: http://stackoverflow.com/questions/3835636/php-replace-last-occurence-of-a-string-in-a-string – Dirk McQuickly May 05 '13 at 20:10
0

What exactly is a comma-delimited string, and what does removing a trailing comma do?

A comma-delimited string is a string that separates parts of a string with commas. like

$a = 'you, should, do, your, homework, before, asking, stuff, like, this, here';

If removing a comma, then there will be fewer parts.

$a = 'you, should, do your homework, before, asking, stuff, like this here';
bestprogrammerintheworld
  • 5,417
  • 7
  • 43
  • 72