Jump to content

PHP explode conundrum.


HCProfessionals

Recommended Posts

I'm trying to add options to products.

 

Currently, I have them in this format: Leather reinforced hilt,5.00::Stabbing tip,3.00::Logo,10.00

 

$option_results = mysql_query("SELECT product_options FROM products WHERE product_id='".$product."'");
   while($option_row = mysql_fetch_array($option_results)){
         $option = explode("::", $option_row[0]);
         $option_part = explode(",", $option[0]);
         $option_part[0] = $option_name;
         $option_part[1] = $option_price;
         echo "<li><a href=\"#\">".$option_name.", Add $".$option_price."</a></li>";
    }

 

I would like the output to be:

 

<li><a href="#">Leather reinforced hilt, Add $5.00</a></li>

<li><a href="#">Stabbing tip, Add $3.00</a></li>

<li><a href="#">Logo, Add $10.00</a></li>

Link to comment
Share on other sites

I'm not really getting anywhere...

 

					$option_results = mysql_query("SELECT product_options FROM products WHERE product_id='".$product."'");
					while($option_row = mysql_fetch_array($option_results)){
							$sep_option = explode("::", $option_row[0]);
							foreach ($sep_option as $sep_result)
							{
								$option_part = explode(",", $sep_result);
								$option_part[0] = $option_name;
								$option_part[1] = $option_price;
								echo "<li class=\"product\" id=\"option-".$option_name."\"><input class=\"purchase\" type=\"button\" value=\"Add to cart\"><span class=\"title\">".$option_name."</span>, Add $<span class=\"price\">".$option_price."</span></li>";
							}

					}

Link to comment
Share on other sites

As was said before, you're not defining $option_name or $option_price. You're doing those statements backwards, you're saying that the first key in $option_part should be set to the value within $option_name. $option_name does not exist. Switch it around.

Link to comment
Share on other sites

As was said before, you're not defining $option_name or $option_price. You're doing those statements backwards, you're saying that the first key in $option_part should be set to the value within $option_name. $option_name does not exist. Switch it around.

 

Wow, totally missed that. Thank You!!!!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.